【问题标题】:flutter error all of a sudden the named parameter child isnt defined突然颤动错误命名参数子未定义
【发布时间】:2021-06-26 05:08:49
【问题描述】:

我换了笔记本电脑,重新安装了 android studio 和 flutter

之前正常运行且没有任何错误和警告的应用突然开始抛出错误和警告

这是错误所在的代码:

          onTap: () async {
                          showDialog(
                              context: context,
                              child: Container(
                                  height: 30,
                                  width: 30,
                                  child: Center(
                                      child: CupertinoActivityIndicator(
                                    key: UniqueKey(),
                                    radius: 20,
                                    animating: true,
                                  ))));
                          await handleFacebookLogin(context).then((user) {
                            navigationCheck(user, context);
                          }).then((_) {
                            Navigator.pop(context);
                          }).catchError((e) {
                            Navigator.pop(context);
                          });
                        },

它以前工作得很好,但它在新安装时抛出错误似乎有点奇怪,有人可以指导我这里是什么问题吗?

到目前为止我所做的尝试:

  1. 运行清理项目缓存

    flutter clean cache

然后使缓存失效/重启 Android Studio

  1. 重启飞镖分析服务器

但问题还是一样

【问题讨论】:

    标签: flutter android-studio


    【解决方案1】:

    showDialog 需要 contextbuilder,而不是 child

    试试这个:

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

    【讨论】:

    • 这是因为 dart/flutter 最近的一些更新吗?因为相同的代码在 10 到 15 天前还在工作,现在却出现了问题?
    • 我不知道。你在之前的项目中使用过相同的 Dart 版本吗?
    • 是的,它摆脱了上面提到的错误,但是发生了一些奇怪的事情,现在它导致了编译错误,这真的很奇怪,无论如何我会开始并一次调试一个错误跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-30
    相关资源
    最近更新 更多