diff --git a/using_snackbar/lib/main.dart b/using_snackbar/lib/main.dart index 9ec1d96..1ad0c80 100644 --- a/using_snackbar/lib/main.dart +++ b/using_snackbar/lib/main.dart @@ -12,8 +12,37 @@ class ContactPage extends StatelessWidget { title: new Text("Using SnackBar"), ), body: new Center( - child: new Text("Hello World!"), + child: new MyButton(), ), ); } } + +class MyButton extends StatelessWidget { + @override + Widget build(BuildContext context) { + return new RaisedButton( + child: new Text('Show SnackBar'), + // On pressing the raised button + onPressed: () { + // show snackbar + Scaffold.of(context).showSnackBar(new SnackBar( + // set content of snackbar + content: new Text("Hello! I am SnackBar :)"), + // set duration + duration: new Duration(seconds: 3), + // set the action + action: new SnackBarAction( + label: "Hit Me (Action)", + onPressed: () { + // When action button is pressed, show another snackbar + Scaffold.of(context).showSnackBar(new SnackBar( + content: new Text( + "Hello! I am shown becoz you pressed Action :)"), + )); + }), + )); + }, + ); + } +}