我想用单独的onPressed函数在ListView.builder项的左侧显示IconButton

时间:2020-03-18 19:50:12

标签: flutter flutter-layout

Please see this -> Listview with left IconButton Picture

我想在ListView.builder项的左侧显示IconButton,并且每个IconButton对于listview的所有项都应具有单独的onPressed函数。

与所附图片完全一样。

我该如何实现?请帮忙.. 我尝试使用Row添加IconButton,但是这样,整个列表视图项只能得到一个相同的onPressed函数。

ListView.builder(
              itemCount: _data.length + _selectedList.length,
              itemBuilder: (BuildContext context, int index) {
                int a = index - _data.length + 1;
                if (index < _data.length) {
                  return Column(
                    children: <Widget>[
                      Row(
                        children: <Widget>[
               // I tried adding like this, but It have same OnPressed function for all the items of the listview
                           IconButton(
                            icon: info_click ? Icon(Icons.info,color: 
                      Color(0xff06a1b4),):Icon(Icons.info),
                            onPressed: ()
                            {
                              info_click=true;
                              setState(() {
                              _showFormDialog();
                              });
                            },
                          ),
                          Expanded(
                            child: Container(
                                margin: new EdgeInsets.fromLTRB(0, 7, 0, 0),
                                child: InkWell(
                                  //highlightColor: Colors.red,
                                  splashColor: Color(0xff06a1b4),
                                  onTap: () {
                                    setState(() {
                                      bool value;
                                      if (sampleData[index].isSelected) {
                                        value = false;
                                      } else {
                                        value = true;
                                      }

                                      if (value == false) {
                                        _selectedList.remove(_items[index]);
                                        sampleData[index].isSelected =
                                            false;
                                      } else {
                                        _selectedList.add(_items[index]);
                                        sampleData[index].isSelected = true;
                                      }
                                    });
                                  },
                                  child: new CheckItem(sampleData[index]),
                                )),
                          )
                        ],
                      ),
                      Container(
                        margin: EdgeInsets.only(top: 10),
                        child: AnimatedContainer(
                          margin: EdgeInsets.only(top: 0, bottom: 7),
                          height: _protocolHintHeight[index],
                          width: MediaQuery.of(context).size.height - 350,
                          duration: Duration(milliseconds: 250),
                          curve: Curves.linear,
                          child: Card(
                              child: Padding(
                                  padding:
                                      EdgeInsets.fromLTRB(10.0, 4, 10.0, 4),
                                  child: FittedBox(
                                    fit: BoxFit.contain,
                                    child: AutoSizeText(
                                        _protocolHIntText[index]),
                                  ))),
                        ),
                      )
                    ],
                  );

                } else if (index == _data.length) {
                  return Container(
                      // margin: new EdgeInsets.fromLTRB(20, 7, 0, 0),
                      child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      SquareButton(
                        text: "Order of Service",
                      ),
                      Container(
                          height: 35,
                          margin: EdgeInsets.only(left: 20),
                          child: ListTile(
                            // dense: true,
                            title: Text(
                              "$a. " + _selectedList[index - _data.length],
                              textScaleFactor: 1.1,
                            ),
                          ))
                    ],
                  ));
                } else {
                  return Container(
                      height: 35,
                      margin: EdgeInsets.only(left: 20),
                      child: ListTile(
                        // dense: true,
                        title: Text(
                          "$a. " + _selectedList[index - _data.length],
                          textScaleFactor: 1.1,
                          style: TextStyle(fontFamily: "OpenSans"),
                        ),
                      ));
                }
              },
            )),

0 个答案:

没有答案