Skip to content

Commit 31caa13

Browse files
authored
Create displaying-snackbars-in-flutter.dart
1 parent 007e480 commit 31caa13

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Want to support my work 🤝? https://buymeacoffee.com/vandad
2+
3+
class HomePage extends StatelessWidget {
4+
@override
5+
Widget build(BuildContext context) {
6+
return Scaffold(
7+
appBar: AppBar(
8+
title: Text('Hello world'),
9+
),
10+
body: Center(
11+
child: TextButton(
12+
onPressed: () {
13+
final now = DateFormat('kk:mm:ss').format(DateTime.now());
14+
ScaffoldMessenger.of(context).removeCurrentSnackBar();
15+
ScaffoldMessenger.of(context).showSnackBar(
16+
SnackBar(
17+
behavior: SnackBarBehavior.floating,
18+
elevation: 5.0,
19+
backgroundColor:
20+
Colors.blue[600]!.withOpacity(0.8).withAlpha(200),
21+
shape: RoundedRectangleBorder(
22+
borderRadius: BorderRadius.circular(10),
23+
side: BorderSide(
24+
color: Colors.black.withOpacity(0.4),
25+
width: 3.0,
26+
),
27+
),
28+
content: Text('Some text $now'),
29+
),
30+
);
31+
},
32+
child: Text('Show toast'),
33+
),
34+
),
35+
);
36+
}
37+
}

0 commit comments

Comments
 (0)