Answers for "snackbar flutter"

9

flutter snackbar

ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                content: Text("Your Text"),
                duration: Duration(milliseconds: 300),
              ));
Posted by: Guest on July-08-2021
7

flutter snackbar showing error

You can show material design snackbars using the following code:

Scaffold.of(context).showSnackBar(SnackBar(
      content: Text("New Notification"),
    ));
 
In some cases, this will throw an error and it can be resolved using a workaround:

//Declare a GlobalKey
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();

//Assing this key to the scaffold
Scaffold(
  key: _scaffoldKey,
  body: ...
)

//finally in the topmost code use this key in the following way
_scaffoldKey.showSnackBar(SnackBar(
      content: Text("New Notification"),
    ));
Posted by: Guest on May-14-2020
5

flutter snackbar

final snackBar = SnackBar(
            content: const Text('Yay! A SnackBar!'),
            action: SnackBarAction(
              label: 'Undo',
              onPressed: () {},
            ),
          );
ScaffoldMessenger.of(context).showSnackBar(snackBar);
Posted by: Guest on August-21-2021
2

flutter snackbar duration

ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            duration: const Duration(milliseconds: 4000), // default 4s
            content: const Text('Awesome Snackbar!'),
          ),
        );
Posted by: Guest on August-24-2021
3

snackbar flutter

ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            duration: const Duration(milliseconds: 5000), 
            content: const Text('Awesome Snackbar!'),
          ),
        );
Posted by: Guest on November-17-2021
3

snackbar in flutter

final snackBar = SnackBar(content: Text('Yay! A SnackBar!'));

// Find the ScaffoldMessenger in the widget tree
// and use it to show a SnackBar.
ScaffoldMessenger.of(context).showSnackBar(snackBar);
Posted by: Guest on March-04-2021

Browse Popular Code Answers by Language