【问题标题】:Flutter: how to override functionFlutter:如何覆盖函数
【发布时间】:2019-10-29 14:11:35
【问题描述】:

基本上,我想覆盖位于packages/flutter/lib/src/material/dialog.dart的祖先showDialog函数的一些道具

我想更改 barrierColor 属性并从 showGeneralDialog 构建器方法中删除 SafeArea 小部件。

//...
Future<T> showDialog<T>({
  @required BuildContext context,
  bool barrierDismissible = true,
  @Deprecated(
    'Instead of using the "child" argument, return the child from a closure '
    'provided to the "builder" argument. This will ensure that the BuildContext '
    'is appropriate for widgets built in the dialog.'
  ) Widget child,
  WidgetBuilder builder,
}) {
  assert(child == null || builder == null);
  assert(debugCheckHasMaterialLocalizations(context));

  final ThemeData theme = Theme.of(context, shadowThemeOnly: true);
  return showGeneralDialog(
    context: context,
    pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) {
      final Widget pageChild = child ?? Builder(builder: builder);
      return SafeArea( // <-- !remove SafeArea widget!
        child: Builder(
          builder: (BuildContext context) {
            return theme != null
                ? Theme(data: theme, child: pageChild)
                : pageChild;
          }
        ),
      );
    },
    barrierDismissible: barrierDismissible,
    barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
    barrierColor: Colors.black54, // <-- !change the color!
    transitionDuration: const Duration(milliseconds: 150),
    transitionBuilder: _buildMaterialDialogTransitions,
  );
}

可以在main.dart 文件中做吗?如果可以,谁能举个例子吗?

【问题讨论】:

    标签: flutter dart flutter-layout flutter-dependencies


    【解决方案1】:

    您可以将该函数复制/粘贴到您的 main.dart 文件中,在那里更改名称和屏障颜色,它会起作用,因为您可以使用 showGeneralDialog

    【讨论】:

      猜你喜欢
      • 2011-07-21
      • 2016-05-04
      • 2012-10-16
      • 2020-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多