showFxOverlay<Result, T> function

Future<Result?> showFxOverlay<Result, T>(
  1. BuildContext context, {
  2. bool cancelable = true,
  3. bool useSafeArea = true,
  4. FxOverlayType type = FxOverlayType.bottomSheet,
  5. ScrollController? scrollController,
  6. FxBottomSheetOptions bottomSheetOptions = const FxBottomSheetOptions(),
  7. required FxOverlayOptions<T> options,
})

Implementation

Future<Result?> showFxOverlay<Result, T>(
  BuildContext context, {
  bool cancelable = true,
  bool useSafeArea = true,
  FxOverlayType type = FxOverlayType.bottomSheet,
  ScrollController? scrollController,
  FxBottomSheetOptions bottomSheetOptions = const FxBottomSheetOptions(),
  required FxOverlayOptions<T> options,
}) {
  final themeData = context.themeData.overlayTheme;
  DraggableScrollableController? sheetController;

  if (type == FxOverlayType.bottomSheet) {
    sheetController ??= DraggableScrollableController();
  }

  return switch (type) {
    FxOverlayType.bottomSheet => showModalBottomSheet<Result>(
      context: context,
      backgroundColor: Colors.transparent,
      isDismissible: cancelable,
      isScrollControlled: bottomSheetOptions.canFullHeight,
      builder: (context) => DraggableScrollableSheet(
        expand: false,
        maxChildSize: bottomSheetOptions.maxChildSize,
        minChildSize: bottomSheetOptions.minChildSize,
        controller: sheetController!,
        initialChildSize: bottomSheetOptions.initialChildSize,
        builder: (context, controller) => FxBottomSheetShell<T>(
          type: type,
          options: options,
          useSafeArea: useSafeArea,
          sheetController: sheetController!,
          scrollController: scrollController ?? controller,
          bottomSheetOptions: bottomSheetOptions,
        )
      )
    ),
    FxOverlayType.modal => showGeneralDialog<Result>(
      context: context,
      barrierColor: themeData.barrierColor,
      fullscreenDialog: true,
      transitionDuration: context.componentTheme
        .switchingViewTransition().duration,
      transitionBuilder: (context, animation, _, child) => context.componentTheme
        .switchingViewTransition()
        .transitionBuilder(child, animation),
      pageBuilder: (context, _, _) => Material(
        color: Colors.transparent,
        child: FxBottomSheetShell<T>(
          type: type,
          useSafeArea: useSafeArea,
          options: options,
          scrollController: scrollController
        )
      )
    ),
    FxOverlayType.dialog => showDialog<Result>(
      context: context,
      barrierColor: themeData.barrierColor,
      barrierDismissible: cancelable,
      builder: (context) => Center(child: Material(
        color: Colors.transparent,
        child: FxBottomSheetShell<T>(
          type: type,
          options: options,
          useSafeArea: useSafeArea,
          scrollController: scrollController
        )
      ))
    )
  };
}