Flutter:如何重写功能

问题描述 投票:0回答:1

基本上,我想重写位于showDialog中的祖先packages/flutter/lib/src/material/dialog.dart函数的一些属性>

我想更改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文件中执行吗?如果是,谁能举个例子吗?

基本上,我想覆盖位于packages / flutter / lib / src / material / dialog.dart中的祖先showDialog函数的一些道具,我想更改barrierColor属性并删除SafeArea ...

flutter dart flutter-layout flutter-dependencies
1个回答
0
投票

您可以仅将该函数复制/粘贴到main.dart文件中,在其中更改名称和barrierColor,因为您可以使用showGeneralDialog,所以它可以工作

© www.soinside.com 2019 - 2024. All rights reserved.