【问题标题】:The named parameter 'child' isn't defined未定义命名参数“child”
【发布时间】:2021-06-15 14:59:39
【问题描述】:
showDialog(
  context: context,
  barrierDismissible: false,
  child: AlertDialog( // this line error
    shape: defaultCardBorder(),
    title: Row(
      children: [
        _icon,
        SizedBox(width: 10),
        Expanded(child: Text(_title, style: TextStyle(fontSize: 22)))
      ],
    ),
    content: Text(
      message,
      style: TextStyle(fontSize: 18),
    ),
    actions: [
      /// Negative button
      negativeAction == null
          ? Container(width: 0, height: 0)
          : FlatButton(
              onPressed: negativeAction,
              child: Text(negativeText ?? "CANCEL",
                  style: TextStyle(fontSize: 18, color: Colors.grey))),

      /// Positive button
      FlatButton(
          onPressed: positiveAction ?? () => Navigator.of(context).pop(),
          child: Text(positiveText ?? "OK",
              style: _textStyle)),
    ],
  ));

>如何在flutter中解决这个问题 子行错误。错误是未定义命名参数“child”。 未定义命名参数“child”。 尝试将名称更正为现有命名参数的名称,或使用

定义命名参数

【问题讨论】:

    标签: flutter


    【解决方案1】:

    我猜你使用的是 Flutter 2.0。自从这次更新AlertDialog 不再有子属性。相反,您必须声明一个 builder

    showDialog(
              context: context,
              barrierDismissible: false,
              builder: (BuildContext context) => AlertDialog(
                title: Text('MyTitle'),
                content: Container(),
              ),
            );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-04
      • 2021-05-13
      • 2020-07-23
      • 2020-02-13
      • 2022-11-01
      • 2020-06-24
      • 2018-05-14
      相关资源
      最近更新 更多