updated: implemented using_snackbar example

This commit is contained in:
Nishant Srivastava
2018-01-20 03:52:02 +05:30
parent 959888ab4b
commit 9afe86d139

View File

@ -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 :)"),
));
}),
));
},
);
}
}