I want to create a simple snackbar that come from top of the screen instesd of bottom.In flutter i have used native snackbar but it does not have such feature.
top-snackbar-flutter If you need to show the user some information in a nice way, you can use this package. The API is as simple as API for regular Material method showDialog . If you need to use your own widget to display, you can pass it into showTopSnackBar function.
of() is deprecated for showing SnackBars, use ScaffoldMessenger instead.
you probably have a parent widget that contains Scaffold as well. Create a scaffoldKey for that and pass it to your child widget that have to show the Snakcbar . Note that you can't use Sanckbar without Scaffold widget.
You can use https://pub.dartlang.org/packages/flushbar
RaisedButton( child: Text('Show Top Snackbar'), onPressed: () { Flushbar( flushbarPosition: FlushbarPosition.TOP, ) ..title = "Hey Ninja" ..message = "Lorem Ipsum is simply dummy text of the printing and typesetting industry" ..duration = Duration(seconds: 3) ..show(context); }, ),
You can set a margin using the device's height to achieve this:
ScaffoldMessenger.of(context).showSnackBar(new SnackBar( content: Text('Snackbar message'), behavior: SnackBarBehavior.floating, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(24), ), margin: EdgeInsets.only( bottom: MediaQuery.of(context).size.height - 100, right: 20, left: 20), ));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With