Posted By

markt22 on 07/18/18


Tagged

flutter dart


Versions (?)

Flutter: Display a snack bar


 / Published in: JavaScript
 

Creates a RaisedButton widget that, when pressed, displays a snack bar

  1. class _MyHomePageState extends State<MyHomePage> {
  2. @override
  3. Widget build(BuildContext context) {
  4. return new Scaffold(
  5. appBar: new AppBar(
  6. title: Text(widget.title),
  7. ),
  8. body: Center(child: Builder(builder: (context) { //we must wrap in a builder so that Scaffold.of(context) can find a scaffold
  9. return RaisedButton(
  10. onPressed: () {
  11. final snackBar = SnackBar(
  12. content: Text('Yay! A SnackBar!'),
  13. );
  14.  
  15. // Find the Scaffold in the Widget tree and use it to show a SnackBar!
  16. Scaffold.of(context).showSnackBar(snackBar);
  17. },
  18. child: Text('Show SnackBar'),
  19. );
  20. })));
  21. }
  22. }

Report this snippet  

You need to login to post a comment.