show<T> static method

Future<T?> show<T>(
  1. BuildContext context, {
  2. required Widget gallery,
})

Displays the provided gallery in a ModalPopup.

Implementation

static Future<T?> show<T>(
  BuildContext context, {
  required Widget gallery,
}) async {
  final style = Theme.of(context).style;

  final ModalRoute<T> route;

  if (context.isMobile) {
    route = MaterialPageRoute<T>(
      builder: (BuildContext context) {
        return Material(
          type: MaterialType.canvas,
          color: style.colors.onBackground,
          child: Scaffold(
            backgroundColor: style.colors.onBackground,
            body: gallery,
          ),
        );
      },
    );
  } else {
    route = RawDialogRoute<T>(
      barrierColor: style.colors.backgroundGallery,
      barrierDismissible: true,
      pageBuilder: (_, _, _) {
        return CustomSafeArea(
          child: Material(type: MaterialType.transparency, child: gallery),
        );
      },
      barrierLabel: MaterialLocalizations.of(
        context,
      ).modalBarrierDismissLabel,
      transitionDuration: const Duration(milliseconds: 300),
      transitionBuilder: (_, Animation<double> animation, _, Widget child) {
        return FadeTransition(
          opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
          child: child,
        );
      },
    );
  }

  router.obscuring.add(route);

  try {
    return await Navigator.of(context, rootNavigator: true).push<T>(route);
  } finally {
    router.obscuring.remove(route);
  }
}