onShowDialog method

Future<SilentActionResult> onShowDialog(
  1. NodeSpec action,
  2. ActionContext context
)

Implementation

Future<SilentActionResult> onShowDialog(
    NodeSpec action, ActionContext context) async {
  final props = action.props;
  final screen =
      Schema.getScreen(props["jumpToScreen"] ?? props["jumpToRoute"]);
  final screenState = props["state"];
  if (screen == null) {
    return SilentActionResult(false);
  }

  tailFunc(value) {
    final onPopAction = action.actions["onPop"];
    if (onPopAction != null && context.buildContext.mounted) {
      Lowder.actions.run(
        context.buildContext,
        NodeSpec.fromMap(onPopAction),
        context.state,
        value,
        context.actionContext,
      );
    }
  }

  getDialog(context) => Dialog(
        shape: Lowder.properties.build("ShapeBorder", props["shape"]),
        backgroundColor: tryParseColor(props["backgroundColor"]),
        insetPadding: Lowder.properties.getInsets(props["padding"]),
        alignment: Lowder.properties.build("Alignment", props["alignment"]),
        elevation: tryParseDouble(props["elevation"]),
        child:
            Lowder.widgets.buildScreen(context, screen, state: screenState),
      );

  showGeneralDialog(
    context: context.buildContext,
    barrierLabel: "",
    barrierDismissible: parseBool(props["barrierDismissible"]),
    barrierColor: parseColor(props["barrierColor"],
        defaultColor: const Color(0x80000000)),
    pageBuilder: (context, anim1, anim2) => getDialog(context),
    transitionBuilder:
        Types.routeTransitionBuilder.build(props["transition"]),
    transitionDuration: Duration(
        milliseconds:
            parseInt(props["transitionDuration"], defaultValue: 200)),
  ).then((value) => tailFunc(value));
  return SilentActionResult(true);
}