---
# System prepended metadata

title: 『Flutter』Scaffold 報錯
tags: [Flutter]

---

# 『Flutter』Scaffold 報錯
###### tags: `Flutter`


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

使用Builder

```=

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text('Demo')
    ),
    body: Builder(
      // Create an inner BuildContext so that the onPressed methods
      // can refer to the Scaffold with Scaffold.of().
      builder: (BuildContext context) {
        return Center(
          child: RaisedButton(
            child: Text('SHOW A SNACKBAR'),
            onPressed: () {
              Scaffold.of(context).showSnackBar(SnackBar(
                content: Text('Hello!'),
              ));
            },
          ),
        );
      },
    ),
  );
}
```

## 參考
https://juejin.im/post/5d9f010d6fb9a04e366a3474