Shows a persistent material design bottom sheet.
A persistent bottom sheet shows information that supplements the primary content of the app. A persistent bottom sheet remains visible even when the user interacts with other parts of the app.
A closely related widget is a modal bottom sheet, which is an alternative to a menu or a dialog and prevents the user from interacting with the rest of the app. Modal bottom sheets can be created and displayed with the showModalBottomSheet function.
Returns a contoller that can be used to close and otherwise manipulate the button sheet.
See also:
- BottomSheet, which is the widget typicaly returned by the
builder. - showModalBottomSheet, which can be used to display a modal bottom sheet.
- Scaffold.of, for information about how to obtain the ScaffoldState.
- material.google.com/components/bottom-sheets.html#bottom-sheets-persistent-bottom-sheets
Source
PersistentBottomSheetController<dynamic/*=T*/> showBottomSheet/*<T>*/(WidgetBuilder builder) {
if (_currentBottomSheet != null) {
_currentBottomSheet.close();
assert(_currentBottomSheet == null);
}
Completer<dynamic/*=T*/> completer = new Completer<dynamic/*=T*/>();
GlobalKey<_PersistentBottomSheetState> bottomSheetKey = new GlobalKey<_PersistentBottomSheetState>();
AnimationController controller = BottomSheet.createAnimationController(this)
..forward();
_PersistentBottomSheet bottomSheet;
LocalHistoryEntry entry = new LocalHistoryEntry(
onRemove: () {
assert(_currentBottomSheet._widget == bottomSheet);
assert(bottomSheetKey.currentState != null);
bottomSheetKey.currentState.close();
if (controller.status != AnimationStatus.dismissed)
_dismissedBottomSheets.add(bottomSheet);
setState(() {
_currentBottomSheet = null;
});
completer.complete();
}
);
bottomSheet = new _PersistentBottomSheet(
key: bottomSheetKey,
animationController: controller,
onClosing: () {
assert(_currentBottomSheet._widget == bottomSheet);
entry.remove();
},
onDismissed: () {
if (_dismissedBottomSheets.contains(bottomSheet)) {
setState(() {
_dismissedBottomSheets.remove(bottomSheet);
});
}
},
builder: builder
);
ModalRoute.of(context).addLocalHistoryEntry(entry);
setState(() {
_currentBottomSheet = new PersistentBottomSheetController<dynamic/*=T*/>._(
bottomSheet,
completer,
() => entry.remove(),
(VoidCallback fn) { bottomSheetKey.currentState?.setState(fn); }
);
});
return _currentBottomSheet;
}