简体   繁体   English

OnPressed FloatingActionButton设置图标

[英]OnPressed FloatingActionButton set Icon

    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)
                          )

                        )
]
                    ),


              )),
        );
      }

  }

This is the updated part of the previous post, as you can see I have done what I have been advised for, however when I hit the Floating Action Button, the icon does not change within it. 这是前一篇文章的更新部分,您可以看到我已完成建议的操作,但是当我按下“浮动操作按钮”时,该图标在其中不会发生变化。 This is the updated part of the previous post, as you can see I have done what I have been advised for, however when I hit the Floating Action Button, the icon does not change within it. 这是前一篇文章的更新部分,您可以看到我已完成建议的操作,但是当我按下“浮动操作按钮”时,该图标在其中不会发生变化。

1) Declare icon to be displayed Globally 1)声明要全局显示的图标

IconData icon = Icons.check_circle;

2) Use this icon instead of hardcoded icon 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)
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM