Saturday, March 2, 2024

Flutter Load Modal from Bottom

Create awesome and powerful modal bottom sheets.


Create your own
Bar Modal
Material Modal

Try it

Explore the Web Demo or clone the repository.

Why not showModalBottomSheet?

Inspired by showModalBottomSheet, it completes with some must-need features:

  • Support for inside scrollview + dragging down to close (showModalBottomSheet won’t work correctly with scrollviews.
  • Support for WillPopScope to prevent closing the dialog.
  • Support for scroll to top when tapping status bar (iOS only)
  • Cupertino modal bottom sheet
  • Create custom modal bottom sheet

First Steps

How to install it? Follow Instructions

Material Modal BottomSheet

  context: context,
  builder: (context) => Container(),

Generic params for all modal bottom sheets

bool expand = falseThe expand parameter specifies id the modal bottom sheet will be full screen size or will fit the content child
bool useRootNavigator = falseThe useRootNavigator parameter ensures that the root navigator is used to display the bottom sheet when set to true. This is useful in the case that a modal bottom sheet needs to be displayed above all other content but the caller is inside another Navigator.
bool isDismissible = trueThe isDismissible parameter specifies whether the bottom sheet will be dismissed when user taps on the scrim.
Color barrierColorThe barrierColor parameter controls the color of the scrim for this route
bool enableDrag = trueThe enableDrag parameter specifies whether the bottom sheet can be dragged up and down and dismissed by swiping downwards.
AnimationController secondAnimationThe secondAnimation parameter allows you to provide an animation controller that will be used to animate push/pop of the modal route. Using this param is advised against and will be probably removed in future versions
bool bounce = falseThe bounce parameter specifies if the bottom sheet can go beyond the top boundary while dragging
Duration duration = const Duration(milliseconds: 400)The duration of modal opening
double closeProgressThreshold = 0.6The closeProgressThreshold specifies when the bottom sheet will be dismissed when user drags it.

Material params

The optional backgroundColorelevationshape, and clipBehavior parameters can be passed in to customize the appearance and behavior of material bottom sheets.

Using it with a scroll view inside

Assign the ModalScrollController.of(context) to your primary modal to sync the scroll with the modal’s drag

  context: context,
  builder: (context) => SingleChildScrollView(
    controller: ModalScrollController.of(context),
    child: Container(),

Cupertino Modal BottomSheet

iOS 13 came with an amazing new modal navigation and now it is available to use with Flutter.

  context: context,
  builder: (context) => Container(),

See generic paramameter in the Material section above

Cupertino specific params

The optional backgroundColor parameters can be passed in to customize the backgroundColor cupertino bottom sheets. Useful if you want a blurred transparent background as the example Cupertino Photo Share

CAUTION!: To animate the previous route some changes are needed.

Why? MaterialPageRoute and CupertinoPageRoute do not allow animated translation to/from routes that are not the same type.

Replace your current route class with MaterialWithModalsPageRoute.

Notice this route type behaves the same as MaterialPageRoute and supports custom PageTransitionsBuilder and PageTransitionsTheme. How can I replace my current route?

Is there an alternative in case I can’t change my current route? Yes! Learn how to animate previous route with CupertinoScaffold:

It supports native features as bouncing, blurred background, dark mode, stacking modals and inside navigation.

Push new views inside the modal bottom sheet

a. If you want to push a new modal bottom sheet just call showCupertinoModalBottomSheet again (works with both options)

b. For inside navigaton add a new Navigator or CupertinoTabScaffold inside

c. Also it supports flutter features as WillPopScope to prevent the modal bottom to be closed.

Build other BottomSheets

Try showBarModalBottomSheet for a bottomSheet with the appearance used by Facebook or Slack