Answers for "flutter Scaffold.of() called with a context that does not contain a Scaffold"

0

flutter Scaffold.of() called with a context that does not contain a Scaffold

This exception happens because you are using the context of the widget that
instantiated Scaffold.
Not the context of a child of Scaffold.
You can solve this by just using a different context :

Scaffold(
    appBar: AppBar(
        title: Text('SnackBar Playground'),
    ),
    body: Builder(
        builder: (context) => 
            Center(
            child: RaisedButton(
            color: Colors.pink,
            textColor: Colors.white,
            onPressed: () => _displaySnackBar(context),
            child: Text('Display SnackBar'),
            ),
        ),
    ),
);
Posted by: Guest on September-05-2021

Code answers related to "flutter Scaffold.of() called with a context that does not contain a Scaffold"

Browse Popular Code Answers by Language