How to show SnackBar in Flutter

后端 未结 3 1106
不思量自难忘°
不思量自难忘° 2021-01-25 08:23

I want to show a SnackBar Widget when the bottom tab is clicked. I am trying to show it as:

Scaffold.of(context).showSnackBar(new SnackBar(
                cont         


        
3条回答
  •  醉话见心
    2021-01-25 09:24

    Unfortunately I am not able to upgrade my Flutter version at the moment, However, from what I understand, you are trying to show a SnackBar only when Live Icon is pressed.

    So you may want to make the Live Icon into an IconButton instead and use its onPressed property on its own instead of using the onTap property of the BottomNavigationBar, then wrap the IconButton within a Builder, something similar to the following:

    new BottomNavigationBar(
              labels: [
                new DestinationLabel(title: new Text("Live"),
                  icon: new Builder(builder: (BuildContext context) {
                    return new IconButton(icon: new Icon(Icons.live_tv),
                        onPressed: () {
                          Scaffold.of(context).showSnackBar(
                              new SnackBar(content: new Text("Live Clicked")));
                        });
                  }),
                ),
                new DestinationLabel(icon: new Icon(Icons.date_range),
                    title: new Text("Matches"),)
    
    
              ],
            )
    

    I am not sure if this is the best practice, our Flutter gurus here always suggest to compose the more complex widgets from multiple classes.

提交回复
热议问题