open static method

Future<void> open({
  1. bool barrierDismissible = false,
  2. bool useSafeArea = true,
  3. bool useRootNavigator = true,
  4. bool scrollable = false,
  5. bool showCloseButton = false,
  6. Image? image,
  7. Widget? title,
  8. required Widget content,
  9. required TdDialogActions actionButton,
})

弹出对话框

Implementation

static Future<void> open({
  bool barrierDismissible = false,
  bool useSafeArea = true,
  bool useRootNavigator = true,
  bool scrollable = false,
  bool showCloseButton = false,
  Image? image,
  Widget? title,
  required Widget content,
  required TdDialogActions actionButton,
}) {
  final completer = Completer<void>();

  final context = TdConfig.instance.context;
  final theme = TdTheme.of(context);

  Navigator.of(context, rootNavigator: useRootNavigator).push(TdDialogRoute(
    builder: (context) {
      final mediaQuery = MediaQuery.sizeOf(context);

      final maxWidth = mediaQuery.width - theme.spacer2 * 2;
      final maxHeight = mediaQuery.height - theme.spacer6 * 2;

      return Center(
        child: ConstrainedBox(
          constraints: BoxConstraints(
            maxWidth: min(320.0, maxWidth),
            maxHeight: maxHeight,
          ),
          child: TdDialog(
            onClosed: () {
              TdPopupPlugin.pop();

              completer.complete();
            },
            scrollable: scrollable,
            showCloseButton: showCloseButton,
            image: image,
            title: title,
            content: content,
            actionButton: actionButton,
          ),
        ),
      );
    },
    barrierColor: theme.maskActive,
    barrierDismissible: barrierDismissible,
    useSafeArea: useSafeArea,
    traversalEdgeBehavior: TraversalEdgeBehavior.closedLoop,
  ));

  return completer.future;
}