OnPressed FloatingActionButton设置图标

时间:2018-06-08 11:10:56

标签: dart flutter

    class Tickets extends StatefulWidget {

      int groupid;
      int event_id;

      Tickets([this.groupid, this.event_id]);

      @override
      _TicketsState createState() => new _TicketsState();
    }
     List<Widget> ListMyWidgets(ticketGroups) {

    IconData icon = Icons.undo;
    List<Widget> list = new List();
    list.add(new CupertinoNavigationBar(
      backgroundColor: Colors.blue,
      leading:
          new Padding(
        padding: new EdgeInsets.all(8.0),
        child: new Text(ticketGroups[0]['ticket_name'],
            style: const TextStyle(
                fontSize: 20.0, fontFamily: 'Poppins', color: Colors.white)),
      ),

      trailing: new Padding(
          padding: new EdgeInsets.all(8.0),
          child: new Text('${ticketGroups.length}',
              style: const TextStyle(
                  fontSize: 20.0, fontFamily: 'Poppins', color: Colors.white))),


    ));


      for (int i = 0; i < ticketGroups.length; i++) {

        list.add(

          new GestureDetector(
              onHorizontalDragStart: (event) {
                print("checked in");
                print(ticketGroups[i]['id']);
                setState(() {
                  _getStatusIn(ticketGroups[i]);
                });
              },
              onDoubleTap: () {
                setState(() {
                  _getStatusOut(ticketGroups[i]);
                });
              },
              child: new Card(
                child: new Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    new Padding(
                      padding: new EdgeInsets.all(8.0),
                      child: new Text(
                          "${ticketGroups[i]['ticket_name']}",
                          style:
                          const TextStyle(
                              fontSize: 15.0, fontFamily: 'Poppins')),
                    ),
                    new Padding(
                        padding: new EdgeInsets.all(8.0),
                        child: new Text(ticketGroups[i]["used"].toString(),
                            style: const TextStyle(
                                fontSize: 15.0, fontFamily: 'Poppins')),
                    ),


                    new SizedBox(
                        height: 30.0,
                        width: 30.0,
                        child: new IconButton(
                          padding: new EdgeInsets.all(0.0),

                          icon: new FloatingActionButton(
                              onPressed: (){
                                setState(() {
                                  icon = Icons.check_circle;
                                });

                              },
                              child: new Icon(icon, size: 20.0),heroTag: null)
                       child: new Icon(icon,size: 25.0),heroTag: null)
                          )

                        )
]
                    ),


              )),
        );
      }

  }

这是上一篇文章的更新部分,因为你可以看到我已经完成了我的建议,但是当我点击浮动操作按钮时,图标不会在其中发生变化。 这是上一篇文章的更新部分,因为你可以看到我已经完成了我的建议,但是当我点击浮动操作按钮时,图标不会在其中发生变化。

1 个答案:

答案 0 :(得分:5)

1)声明要在全球范围内显示的图标

IconData icon = Icons.check_circle;

2)使用此图标代替硬编码图标

new FloatingActionButton(
    onPressed: (){
       setState(() {
           icon = icon == Icons.undo ? Icons.check_circle : Icons.undo; // Change icon and setState to rebuild
       });
    },
    child: new Icon(icon, size: 25.0),heroTag: null)
);