Repository: flutter
Issue: The exception thrown by Overlay.of(context).insert(entry) during build is insufficiently clear. Error message needs to improve.
Labels: c: crash,framework,a: quality,a: error message,has reproducible steps,P2,found in release: 3.3,found in release: 3.6,team-framework,triaged-framework

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.io/
      * https://docs.flutter.io/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill our the template below. Please read
     our guide to filing a bug first:  https://flutter.io/bug-reports/
-->

**Impact**: Overlays not working. This makes a range of UX solutions not usable.

**Description**

The sample app uses a FAB to show a simple overlay. The intent of this is to eventually show as speed dial with multiple buttons revealing when the FAB is tapped. 


## Steps to Reproduce

<!--
     Please tell us exactly how to reproduce the problem you are running into.

     Please attach a small application (ideally just one main.dart file) that
     reproduces the problem. You could use https://gist.github.com/ for this.

     If the problem is with your application's rendering, then please attach
     a screenshot and explain what the problem is.
-->

Use the code from this gist: https://gist.github.com/bizz84/63dea8a27fc9414c9cd830ab908606e2

1. Run the app
2. Tap on the FAB button

## Logs

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue.
-->

```
[+7814 ms] [DEVICE LOG] 2018-09-10 12:19:02.813770+0100  localhost Runner[45112]: (Flutter) flutter: addToOverlay
[   +1 ms] flutter: addToOverlay
[   +8 ms] [DEVICE LOG] 2018-09-10 12:19:02.824778+0100  localhost Runner[45112]: (Flutter) [VERBOSE-2:shell.cc(181)] Dart Error: Unhandled exception:
[        ] [DEVICE LOG] setState() or markNeedsBuild() called during build.
[   +2 ms] [DEVICE LOG] This Overlay widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
[        ] [DEVICE LOG] The widget on which setState() or markNeedsBuild() was called was:
[        ] [DEVICE LOG]   Overlay-[LabeledGlobalKey<OverlayState>#e2ccf](state: OverlayState#15760(entries: [OverlayEntry#a1f34(opaque: false; maintainState: false), OverlayEntry#f3e57(opaque: false; maintainState: true), OverlayEntry#43ab4(opaque: false; maintainState: false)]))
[        ] [DEVICE LOG] The widget which was currently being built when the offending call was made was:
[        ] [DEVICE LOG]   LayoutBuilder(renderObject: _Ren<…>
[  +11 ms] [VERBOSE-2:shell.cc(181)] Dart Error: Unhandled exception:
[        ] setState() or markNeedsBuild() called during build.
[        ] This Overlay widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
[        ] The widget on which setState() or markNeedsBuild() was called was:
[        ]   Overlay-[LabeledGlobalKey<OverlayState>#e2ccf](state: OverlayState#15760(entries: [OverlayEntry#a1f34(opaque: false; maintainState: false), OverlayEntry#f3e57(opaque: false; maintainState: true), OverlayEntry#43ab4(opaque: false; maintainState: false)]))
[        ] The widget which was currently being built when the offending call was made was:
[        ]   LayoutBuilder(renderObject: _Ren<…>
```

**NOTE**: Performing a hot reload causes the overlay to show correctly.

<!--
     Run `flutter analyze` and attach any output of that command below.
     If there are any analysis errors, try resolving them before filing this issue.
-->

```
```

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
[✓] Flutter (Channel beta, v0.7.3, on Mac OS X 10.13.3 17D47, locale en-GB)
    • Flutter version 0.7.3 at /Users/andrea/dev/flutter
    • Framework revision 3b309bda07 (13 days ago), 2018-08-28 12:39:24 -0700
    • Engine revision af42b6dc95
    • Dart version 2.1.0-dev.1.0.flutter-ccb16f7282

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at /Users/andrea/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.3
    • ANDROID_HOME = /Users/andrea/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4.1, Build version 9F2000
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 27.1.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[!] VS Code (version 1.23.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected devices (4 available)
    • iPhone 5  • 05ACE87B-4930-4A7E-A812-1A396896ACBD • ios • iOS 10.3 (simulator)
    • iPhone 6  • 9582A263-6C04-4448-AAD8-2C74B36ED1C1 • ios • iOS 10.3 (simulator)
    • iPhone 5s • 07E98F87-9268-4243-9A81-33F13A059229 • ios • iOS 11.3 (simulator)
    • iPhone X  • 26A68A3D-8AF8-4D8B-B685-2F95BD0988C2 • ios • iOS 11.3 (simulator)

! Doctor found issues in 1 category.
```