Flutter Snackbar

This Article is posted by seven.srikanth at 29-09-2018 07:24:28

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.

##FlutterCentralAds##

Snackbar becomes handy when you want to inform users that cerain action is taking place. 
Here is the code from main.dart file. All you need to do is, create a new flutter app and replace the code with the below code.

##FlutterCentralAds##

import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body:
new Builder(
builder: (BuildContext context) {
return new Center(
child: new RaisedButton(
onPressed: () {
Scaffold.of(context).showSnackBar(SnackBar(
content: new Text('Hello from Snakbar!'),
action: SnackBarAction(
label: "Undo",
onPressed: () {
},
),
));
},
child: new Text("Show Snakbar"),
)
);
},
)
);
}
}

##FlutterCentralAds##

Hope this is useful.

Thanks,
Srikanth

Tags: Flutter Snackbar; Show a message on button click;



0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.



Recent Articles


How to deploy flutter web site on GitHub using peanut

Posted by nikhilchaudhary12155 on 13 Oct 2019 Article


AnimatedPositioned Widget Example in Flutter

Posted by seven.srikanth on 10 Oct 2019 Article


Flutter Open-Source and directory lists

Posted by nishantkotatech on 09 Oct 2019 Article


Flutter Travelling Couple Leading Page - Flutter Web Series 3

Posted by nikhilchaudhary12155 on 05 Oct 2019 Article



© 2018 - Fluttercentral | Email to me - Seven.srikanth@gmail.com