showFutureWidget static method

void showFutureWidget({
  1. required Future<Widget> bottomSheetFuture,
  2. Widget? progressIndicator,
  3. Widget? loadingWidget,
  4. Color? backgroundColor,
  5. double elevation = 10,
  6. RoundedRectangleBorder? shapeBorder,
  7. bool isScrollControlled = true,
})

Displays a modal bottom sheet with content loaded from a Future.

Shows a bottom sheet that displays a loading indicator while waiting for the bottomSheetFuture to complete. Once the future resolves, the returned widget is displayed. Handles error states automatically.

Parameters:

  • bottomSheetFuture: Future that resolves to the widget to display.
  • progressIndicator: Widget shown while loading. Defaults to CircularProgressIndicator.
  • loadingWidget: Alternative loading widget. Defaults to Utils.commonWidgets.getLoadingWidget().
  • backgroundColor: Background color of the sheet. Defaults to transparent.
  • elevation: Shadow elevation of the sheet (defaults to 10).
  • shapeBorder: Custom shape border. Defaults to rounded top corners.
  • isScrollControlled: Whether the sheet height is controlled by content (defaults to true).

States handled:

  • Waiting: Shows progressIndicator or CircularProgressIndicator
  • Error: Shows error message
  • Success: Shows the resolved widget
  • No data: Shows loadingWidget

Example:

GlobalBottomSheet.showFutureWidget(
  bottomSheetFuture: apiService.fetchUserProfile().then(
    (profile) => UserProfileBottomSheet(profile: profile),
  ),
  progressIndicator: CircularProgressIndicator(color: Colors.blue),
  backgroundColor: Colors.white,
);

Implementation

static void showFutureWidget(
    {required Future<Widget> bottomSheetFuture,
    Widget? progressIndicator,
    Widget? loadingWidget,
    Color? backgroundColor,
    double elevation = 10,
    RoundedRectangleBorder? shapeBorder,
    bool isScrollControlled = true}) {
  Get.bottomSheet(
    FutureBuilder<Widget>(
      future: bottomSheetFuture,
      builder: (BuildContext context, AsyncSnapshot<Widget> snapshot) {
        if (snapshot.connectionState == ConnectionState.waiting) {
          return Center(
              child: progressIndicator ?? CircularProgressIndicator());
        } else if (snapshot.hasError) {
          return Center(child: Text('Error: ${snapshot.error}'));
        } else if (snapshot.hasData) {
          return snapshot.data!;
        } else {
          return loadingWidget ?? Utils.commonWidgets.getLoadingWidget();
        }
      },
    ),
    backgroundColor: backgroundColor ?? Colors.transparent,
    elevation: elevation,
    shape: shapeBorder ??
        const RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(20),
            topRight: Radius.circular(20),
          ),
        ),
    isScrollControlled: isScrollControlled,
  );
}