showBottomSheet<T> method

PersistentBottomSheetController<T> showBottomSheet <T>(WidgetBuilder builder)

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 controller that can be used to close and otherwise manipulate the bottom sheet.

To rebuild the bottom sheet (e.g. if it is stateful), call PersistentBottomSheetController.setState on the value returned from this method.

See also:

Implementation

PersistentBottomSheetController<T> showBottomSheet<T>(WidgetBuilder builder) {
  if (_currentBottomSheet != null) {
    _currentBottomSheet.close();
    assert(_currentBottomSheet == null);
  }
  final Completer<T> completer = new Completer<T>();
  final GlobalKey<_PersistentBottomSheetState> bottomSheetKey = new GlobalKey<_PersistentBottomSheetState>();
  final AnimationController controller = BottomSheet.createAnimationController(this)
    ..forward();
  _PersistentBottomSheet bottomSheet;
  final 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)) {
        bottomSheet.animationController.dispose();
        setState(() {
          _dismissedBottomSheets.remove(bottomSheet);
        });
      }
    },
    builder: builder
  );
  ModalRoute.of(context).addLocalHistoryEntry(entry);
  setState(() {
    _currentBottomSheet = new PersistentBottomSheetController<T>._(
      bottomSheet,
      completer,
      entry.remove,
      (VoidCallback fn) { bottomSheetKey.currentState?.setState(fn); }
    );
  });
  return _currentBottomSheet;
}