mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-07-04 09:38:28 +08:00
updated: implemented using_snackbar example
This commit is contained in:
@ -12,8 +12,37 @@ class ContactPage extends StatelessWidget {
|
|||||||
title: new Text("Using SnackBar"),
|
title: new Text("Using SnackBar"),
|
||||||
),
|
),
|
||||||
body: new Center(
|
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 :)"),
|
||||||
|
));
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user