From 1146587cc7cbb60a095a04f2b304a75bf8d78432 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 4 Jan 2017 16:30:37 -0800 Subject: [PATCH] Improve Scaffold.of docs (#7339) The docs now include all the information contained in the exception. Fixes #6994 --- packages/flutter/lib/src/material/scaffold.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index fdadf8863b..115288f8dd 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -465,6 +465,16 @@ class Scaffold extends StatefulWidget { /// } /// ``` /// + /// A more efficient solution is to split your build function into several + /// widgets. This introduces a new context from which you can obtain the + /// [Scaffold]. In this solution, you would have an outer widget that creates + /// the [Scaffold] populated by instances of your new inner widgets, and then + /// in these inner widgets you would use [Scaffold.of]. + /// + /// A less elegant but more expedient solution is assign a [GlobalKey] to the + /// [Scaffold], then use the `key.currentState` property to obtain the + /// [ScaffoldState] rather than using the [Scaffold.of] function. + /// /// If there is no [Scaffold] in scope, then this will throw an exception. /// To return null if there is no [Scaffold], then pass `nullOk: true`. static ScaffoldState of(BuildContext context, { bool nullOk: false }) {