Created
September 9, 2021 07:02
-
-
Save doyle-flutter/fcef511e4563a4bfc3ce2c3fba7afaa4 to your computer and use it in GitHub Desktop.
Dart 2.14 & Flutter 2.5 : ScaffoldMessenger SnackBar & Banner
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) => MaterialApp( | |
| home: MyHomePage(), | |
| ); | |
| } | |
| class MyHomePage extends StatelessWidget{ | |
| @override | |
| Widget build(BuildContext context) => Scaffold( | |
| appBar: AppBar( | |
| title: const Text('Material Banner & SnackBar'), | |
| ), | |
| body: Container( | |
| width: MediaQuery.of(context).size.width, | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
| children: [ | |
| ElevatedButton( | |
| child: const Text('Show MaterialBanner'), | |
| onPressed: () => ScaffoldMessenger.of(context).showMaterialBanner( | |
| MaterialBanner( | |
| content: const Text('Hello, I am a Material Banner'), | |
| leading: const Icon(Icons.info), | |
| backgroundColor: Colors.yellow, | |
| actions: [ | |
| TextButton( | |
| child: const Text('Dismiss'), | |
| onPressed: () => ScaffoldMessenger.of(context) | |
| .hideCurrentMaterialBanner(), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ), | |
| ElevatedButton( | |
| child: const Text('Show SnackBar'), | |
| onPressed: () => ScaffoldMessenger.of(context).showSnackBar( | |
| const SnackBar( | |
| content: Text('Content') | |
| ) | |
| ), | |
| ) | |
| ] | |
| ), | |
| ) | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment