📜  使用不包含脚手架的上下文调用颤振 Scaffold.of() - 无论代码示例

📅  最后修改于: 2022-03-11 14:57:17.380000             🧑  作者: Mango

代码示例1
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'),
            ),
        ),
    ),
);