【问题标题】:Error: No named parameter with the name 'child' in Flutter错误:Flutter 中没有名为“child”的命名参数
【发布时间】:2021-05-21 08:29:22
【问题描述】:

我目前正在对其他人开发的代码进行逆向工程。即使对 Flutter 世界稍有经验,也无法理解错误。可以帮助我完成需要做什么或应该朝哪个方向发展。

 showDialog(
                          context: context,
                          ***child***: Container(
                              height: 30,
                              width: 30,
                              child: Center(
                                  child: CupertinoActivityIndicator(
                                key: UniqueKey(),
                                radius: 20,
                                animating: true,
                              ))));

错误是

错误:没有名为“child”的命名参数。 孩子:容器( ^^^^^

【问题讨论】:

    标签: android flutter flutter-layout


    【解决方案1】:

    您必须添加 builder 才能创建 showDialog

    showDialog(
        context: context,
        builder: (BuildContext context){
         return Container(
              height: 30,
              width: 30,
              child: Center(
                  child: CupertinoActivityIndicator(
                                key: UniqueKey(),
                                radius: 20,
                                animating: true,
                              ))));
        });
    

    【讨论】:

      【解决方案2】:

      有关showDialoghttps://api.flutter.dev/flutter/material/showDialog.html的更多参考请参考以下页面

      showDialog(
            context: context,
            builder: (context) {
              return AlterDialog();
            },
          );
      

      【讨论】:

        【解决方案3】:
        showDialog(
              context: context,
              builder: (_) {
                return Container();
              },
            );
        

        showDialog 没有 child 参数,使用 builder insted child

        【讨论】:

          猜你喜欢
          • 2023-01-16
          • 2022-01-17
          • 2021-12-11
          • 1970-01-01
          • 2023-01-03
          • 2021-06-18
          • 2021-11-26
          • 2022-01-17
          • 1970-01-01
          相关资源
          最近更新 更多