showWidget function

dynamic showWidget(
  1. BuildContext context,
  2. Widget widget,
  3. String routeName, {
  4. Object? routeArguments,
  5. void onClose(
    1. dynamic value
    )?,
  6. void onBeforeShow()?,
  7. bool? progress = true,
  8. bool? forceRoute = false,
})

Implementation

showWidget(
  BuildContext context,
  Widget widget,
  String routeName, {
  Object? routeArguments,
  void Function(dynamic value)? onClose,
  void Function()? onBeforeShow,
  bool? progress = true,
  bool? forceRoute = false,
}) {
  if (onBeforeShow != null) {
    onBeforeShow();
  }

  if (getScreenResolution(context) >= ScreenResolutions.md &&
      forceRoute != true) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          contentPadding: EdgeInsets.zero,
          content: Container(
            width: MediaQuery.of(context).size.width,
            constraints: const BoxConstraints(
              maxWidth: 600,
            ),
            child: widget,
          ),
        );
      },
    ).then((value) {
      if (onClose != null) {
        onClose(value);
      }
    });
  } else {
    Navigator.pushNamed(
      context,
      routeName,
      arguments: routeArguments,
    ).then((value) {
      if (onClose != null) {
        onClose(value);
      }
    });
  }
}