showExpressiveBottomSheet<T> function

Future<T?> showExpressiveBottomSheet<T>({
  1. required BuildContext context,
  2. required WidgetBuilder builder,
  3. bool isDismissible = true,
  4. bool enableDrag = true,
  5. Color? backgroundColor,
  6. double? elevation,
  7. ShapeBorder? shape,
  8. double initialChildSize = 0.5,
  9. double maxChildSize = 0.9,
  10. double minChildSize = 0.25,
  11. bool snap = true,
  12. List<double>? snapSizes,
})

Shows an expressive bottom sheet with spring-based drag physics.

Implementation

Future<T?> showExpressiveBottomSheet<T>({
  required BuildContext context,
  required WidgetBuilder builder,
  bool isDismissible = true,
  bool enableDrag = true,
  Color? backgroundColor,
  double? elevation,
  ShapeBorder? shape,
  double initialChildSize = 0.5,
  double maxChildSize = 0.9,
  double minChildSize = 0.25,
  bool snap = true,
  List<double>? snapSizes,
}) {
  final scheme = Theme.of(context).colorScheme;

  return showModalBottomSheet<T>(
    context: context,
    isDismissible: isDismissible,
    enableDrag: enableDrag,
    backgroundColor: backgroundColor ?? scheme.surfaceContainerLow,
    elevation: elevation ?? 2,
    shape:
        shape ??
        const RoundedRectangleBorder(
          borderRadius: BorderRadius.vertical(top: Radius.circular(28)),
        ),
    isScrollControlled: true,
    builder: (context) {
      return DraggableScrollableSheet(
        initialChildSize: initialChildSize,
        maxChildSize: maxChildSize,
        minChildSize: minChildSize,
        snap: snap,
        snapSizes: snapSizes,
        expand: false,
        builder: (context, scrollController) {
          return Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              // Drag handle
              Padding(
                padding: const EdgeInsets.symmetric(vertical: 12),
                child: Container(
                  width: 32,
                  height: 4,
                  decoration: BoxDecoration(
                    color: scheme.onSurfaceVariant.withValues(alpha: 0.4),
                    borderRadius: BorderRadius.circular(2),
                  ),
                ),
              ),
              Expanded(
                child: SingleChildScrollView(
                  controller: scrollController,
                  child: builder(context),
                ),
              ),
            ],
          );
        },
      );
    },
  );
}