GitHub:https://github.com/happy-python/flutter_demos/tree/master/snackbar_demo
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Flutter Tutorial",
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(title: "SnackBar"),
);
}
}
class HomePage extends StatelessWidget {
final String title;
HomePage({this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
title,
style: TextStyle(fontSize: 15.0),
),
),
body: MySnackBar(),
);
}
}
class MySnackBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
onPressed: () {
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text("Hello From SnackBar"),
duration: Duration(seconds: 3),
),
);
},
color: Colors.amber,
child: Text("Click Me"),
)
],
),
),
);
}
}