<p>In this post, I'm going to share you the code to create a Snackbar in Flutter. Once you run the provided code, this is how a Snackbar will popup on a button click.</p> <p>; background-color: rgb(30, 30, 30); font-family: Consolas, "Courier New", monospace; line-height: 19px; white-space: pre-wrap;](</p> <p>color: #569cd6;](import color: #ce9178;]('package:flutter/material.dart';</p> <p>color: #569cd6;](void color: #dcdcaa;](main() => color: #dcdcaa;](runApp(color: #c586c0;](new color: #4ec9b0;](MyApp());</p> <p>color: #569cd6;](class color: #4ec9b0;](MyApp color: #569cd6;](extends color: #4ec9b0;](StatelessWidget { color: #6a9955;](// This widget is the root of your application.</p> <p>color: #569cd6;](@override</p> <p>color: #4ec9b0;](Widget color: #dcdcaa;](build(color: #4ec9b0;](BuildContext context) { color: #c586c0;](return color: #c586c0;](new color: #4ec9b0;](MaterialApp( title: color: #ce9178;]('Flutter Demo', theme: color: #c586c0;](new color: #4ec9b0;](ThemeData( primarySwatch: color: #4ec9b0;](Colors.blue, ), home: color: #c586c0;](new color: #4ec9b0;](MyHomePage(title: color: #ce9178;]('Flutter Demo Home Page'), ); } }</p> <p>color: #569cd6;](class color: #4ec9b0;](MyHomePage color: #569cd6;](extends color: #4ec9b0;](StatefulWidget { color: #4ec9b0;](MyHomePage({color: #4ec9b0;](Key key, color: #569cd6;](this.title}) : color: #569cd6;](super(key: key); color: #569cd6;](final color: #4ec9b0;](String title; color: #569cd6;](@override</p> <p>color: #4ec9b0;](_MyHomePageState color: #dcdcaa;](createState() => color: #c586c0;](new color: #4ec9b0;](_MyHomePageState(); }</p> <p>color: #569cd6;](class color: #4ec9b0;](_MyHomePageState color: #569cd6;](extends color: #4ec9b0;](State { color: #569cd6;](@override</p> <p>color: #4ec9b0;](Widget color: #dcdcaa;](build(color: #4ec9b0;](BuildContext context) { color: #c586c0;](return color: #c586c0;](new color: #4ec9b0;](Scaffold( appBar: color: #c586c0;](new color: #4ec9b0;](AppBar( title: color: #c586c0;](new color: #4ec9b0;](Text(widget.title), ), body: color: #c586c0;](new color: #4ec9b0;](Builder( builder: (color: #4ec9b0;](BuildContext context) { color: #c586c0;](return color: #c586c0;](new color: #4ec9b0;](Center( child: color: #c586c0;](new color: #4ec9b0;](RaisedButton( onPressed: () { color: #4ec9b0;](Scaffold.color: #dcdcaa;](of(context).color: #dcdcaa;](showSnackBar(color: #4ec9b0;](SnackBar( content: color: #c586c0;](new color: #4ec9b0;](Text(color: #ce9178;]('Hello from Snakbar!'), action: color: #4ec9b0;](SnackBarAction( label: color: #ce9178;]("Undo", onPressed: () , ), )); }, child: color: #c586c0;](new color: #4ec9b0;](Text(color: #ce9178;]("Show Snakbar"), ) ); }, ) ); } }</p> <p>Hope this is useful.</p> <p>Thanks, Srikanth</p>
Flutter Snackbar
This Article is posted by seven.srikanth at 9/29/2018 7:24:28 AM
Check out our other latest articles
Safearea widget - How to avoid visual overlap with Notch on flutter mobile app?How to convert row of widgets into column of widgets in flutter based on screen size?
How to run Flutter programs from GitHub?
How to get screen orientation in flutter?
NavigationRail example in flutter
Tags: Flutter Snackbar; Show a message on button click;
Check out our other latest articles
Safearea widget - How to avoid visual overlap with Notch on flutter mobile app?How to convert row of widgets into column of widgets in flutter based on screen size?
How to run Flutter programs from GitHub?
How to get screen orientation in flutter?
NavigationRail example in flutter