Skip to content

Instantly share code, notes, and snippets.

@Nikhil725051
Created April 20, 2022 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nikhil725051/da37b069ba2d8baf94f1562749d0e94c to your computer and use it in GitHub Desktop.
Save Nikhil725051/da37b069ba2d8baf94f1562749d0e94c to your computer and use it in GitHub Desktop.
class SnackBarRoute extends StatelessWidget {
const SnackBarRoute({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Center(
child: ElevatedButton(
onPressed: () {
//Create the SnackBar
final snackBar = SnackBar(
content: const Text('Hi there! I am a snackbar.'),
action: SnackBarAction(
label: 'Undo',
onPressed: () {
// Place the code to undo the change.
},
),
);
// Use ScaffoldMessenger to show the SnackBar.
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
child: const Text('Show SnackBar'),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment