Display SnackBar in Flutter

前端 未结 15 1443
一个人的身影
一个人的身影 2020-12-04 19:28

I want to display a simple SnackBar inside Flutter\'s stateful widget. My application creates new instance of MaterialApp with a stateful widget ca

15条回答
  •  自闭症患者
    2020-12-04 19:47

    you can use this :

    final _scaffoldKey = GlobalKey();
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          key: _scaffoldKey,
          appBar: AppBar(
    
    
        ),
      }
    }
    

    and then in onPressed() can add this code

    _scaffoldKey.currentState.showSnackBar(
           new SnackBar(
              content: new Text('Hello this is snackbar!')
           )
    );
    

提交回复
热议问题