diff --git a/packages/flutter/lib/src/material/bottom_sheet.dart b/packages/flutter/lib/src/material/bottom_sheet.dart index 5b9849ca8b..530dc5fea2 100644 --- a/packages/flutter/lib/src/material/bottom_sheet.dart +++ b/packages/flutter/lib/src/material/bottom_sheet.dart @@ -221,6 +221,9 @@ Future showBottomSheet({ BuildContext context, GlobalKey place placeholderKey.currentState.child = new _PersistentBottomSheet(route: route); Navigator.of(context).pushEphemeral(route); return completer.future.then((_) { - placeholderKey.currentState.child = null; + // If our overlay has been obscured by an opaque OverlayEntry then currentState + // will have been cleared already. + if (placeholderKey.currentState != null) + placeholderKey.currentState.child = null; }); } diff --git a/packages/flutter/lib/src/material/snack_bar.dart b/packages/flutter/lib/src/material/snack_bar.dart index 3d5d354248..82aa5d561a 100644 --- a/packages/flutter/lib/src/material/snack_bar.dart +++ b/packages/flutter/lib/src/material/snack_bar.dart @@ -108,9 +108,16 @@ Future showSnackBar({ BuildContext context, GlobalKey placehol content: content, actions: actions ); + + // TODO(hansmuller): https://github.com/flutter/flutter/issues/374 + assert(placeholderKey.currentState.child == null); + placeholderKey.currentState.child = snackBar; Navigator.of(context).pushEphemeral(route); return completer.future.then((_) { - placeholderKey.currentState.child = null; + // If our overlay has been obscured by an opaque OverlayEntry currentState + // will have been cleared already. + if (placeholderKey.currentState != null) + placeholderKey.currentState.child = null; }); }