Created
January 8, 2019 15:45
-
-
Save IshanFx/4295a38d795c44b1fc942952af3c273a to your computer and use it in GitHub Desktop.
Snackbar in flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Snackbar', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text("Snackbar"), | |
), | |
body: Builder( | |
builder: (context) => Center( | |
child: RaisedButton( | |
child: Text("Show Snackbar"), | |
onPressed: () { | |
_showSnackbar(context); | |
}, | |
), | |
), | |
), | |
)); | |
} | |
void _showSnackbar(BuildContext context) { | |
final scaff = Scaffold.of(context); | |
scaff.showSnackBar(SnackBar( | |
content: Text("Hay this is it"), | |
backgroundColor: Color.fromARGB(255, 255, 0, 0), | |
duration: Duration(seconds: 5), | |
action: SnackBarAction( | |
label: 'UNDO', onPressed: scaff.hideCurrentSnackBar, | |
), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment