From 9afe86d139f5518a6f720f2c69b5fd5aca7fdc15 Mon Sep 17 00:00:00 2001 From: Nishant Srivastava Date: Sat, 20 Jan 2018 03:52:02 +0530 Subject: [PATCH] updated: implemented using_snackbar example --- using_snackbar/lib/main.dart | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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 :)"), + )); + }), + )); + }, + ); + } +}