【问题标题】:No named parameter with the name 'nullOk' error in flutter颤振中没有名称为“nullOk”的命名参数错误
【发布时间】:2020-11-11 17:14:53
【问题描述】:

在遇到可怕的问题后,我将我的项目传递给另一个项目。但是现在它在尝试运行我的程序后给了我这个错误。这是我以前从未见过的。而且,我没有编辑这些代码,因为它们是库。

../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_neumorphic-3.0.3/lib/src/widget/app_bar.dart:147:57: Error: No named parameter with the name 'nullOk'.
    final ScaffoldState scaffold = Scaffold.of(context, nullOk: true);
                                                        ^^^^^^
../../Developer/flutter/packages/flutter/lib/src/material/scaffold.dart:1918:24: Context: Found this candidate, but the arguments don't match.
  static ScaffoldState of(BuildContext context) {
                       ^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/neumorphic-0.4.0/lib/src/components/app_bar.dart:32:57: Error: No named parameter with the name 'nullOk'.
    final ScaffoldState scaffold = Scaffold.of(context, nullOk: true);
                                                        ^^^^^^
../../Developer/flutter/packages/flutter/lib/src/material/scaffold.dart:1918:24: Context: Found this candidate, but the arguments don't match.
  static ScaffoldState of(BuildContext context) {
                       ^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/neumorphic-0.4.0/lib/src/components/text_field.dart:953:32: Error: No named parameter with the name 'nullOk'.
        MediaQuery.of(context, nullOk: true)?.navigationMode ??
                               ^^^^^^
../../Developer/flutter/packages/flutter/lib/src/widgets/media_query.dart:818:25: Context: Found this candidate, but the arguments don't match.
  static MediaQueryData of(BuildContext context) {
                        ^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/neumorphic-0.4.0/lib/src/neumorphic/theme.dart:390:52: Error: No named parameter with the name 'nullOk'.
      _cupertinoOverrideTheme.resolveFrom(context, nullOk: nullOk),
                                                   ^^^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_neumorphic-3.0.3/lib/src/widget/app_bar.dart:147:57: Error: No named parameter with the name 'nullOk'.
    final ScaffoldState scaffold = Scaffold.of(context, nullOk: true);
                                                        ^^^^^^
../../Developer/flutter/packages/flutter/lib/src/material/scaffold.dart:1918:24: Context: Found this candidate, but the arguments don't match.
  static ScaffoldState of(BuildContext context) {
                       ^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/neumorphic-0.4.0/lib/src/components/app_bar.dart:32:57: Error: No named parameter with the name 'nullOk'.
    final ScaffoldState scaffold = Scaffold.of(context, nullOk: true);
                                                        ^^^^^^
../../Developer/flutter/packages/flutter/lib/src/material/scaffold.dart:1918:24: Context: Found this candidate, but the arguments don't match.
  static ScaffoldState of(BuildContext context) {
                       ^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/neumorphic-0.4.0/lib/src/components/text_field.dart:953:32: Error: No named parameter with the name 'nullOk'.
        MediaQuery.of(context, nullOk: true)?.navigationMode ??
                               ^^^^^^
../../Developer/flutter/packages/flutter/lib/src/widgets/media_query.dart:818:25: Context: Found this candidate, but the arguments don't match.
  static MediaQueryData of(BuildContext context) {
                        ^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/neumorphic-0.4.0/lib/src/neumorphic/theme.dart:390:52: Error: No named parameter with the name 'nullOk'.
      _cupertinoOverrideTheme.resolveFrom(context, nullOk: nullOk),


    Command PhaseScriptExecution failed with a nonzero exit code
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Constructing build description

Could not build the precompiled application for the device.
                                                   ^^^^^^

这是我的 pubspec.yaml

name: Test


environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  rflutter_alert: ^1.0.3
  flutter:
    sdk: flutter
  mqtt_client: ^8.0.0
  provider: ^4.3.2+2
  get_it: ^5.0.1
  vibration: ^1.7.2
  clay_containers: ^0.2.2
  local_auth: ^0.6.2+1
  flutter_secure_storage: ^3.3.3
  neumorphic: ^0.4.0
  shared_preferences: ^0.5.8
  flutter_neumorphic: ^3.0.3
  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:
  uses-material-design: true
  assets:
    - images/homestadelogo.png
    - images/morning.png
  fonts:
    - family: OpenSans
      fonts:
        - asset: fonts/assets/fonts/OpenSans.ttf
    - family: myLamp
      fonts:
        - asset: fonts/assets/fonts/mylamp.ttf

我该怎么办? 如果您需要更多详细信息,请询问我。

【问题讨论】:

  • 你的应用中有脚手架吗?
  • 是的。为什么?基本上在我的 .dart 文件中无处不在
  • 如果需要,我刚刚发布了我的 pubspec.yaml 文件
  • 我也收到此错误,不知道为什么或如何解决它
  • 这似乎是flutter_neumorphic的错误。他们需要对此进行修补以符合当前的 Flutter 标准。

标签: flutter dart


【解决方案1】:

作为空安全迁移后的一部分,已删除多个 nullOk 参数。您可以阅读更多关于corresponding design doc 及其即将推出的migration guide 的信息。

TL;DR 你可以尝试使用.maybeOf(context) 而不是.of(context, nullOk: true);

您可能需要更新依赖项才能使其正常工作。

【讨论】:

  • 我都更新了它们,但它现在给出了错误“错误:找不到方法:'Scaffold.maybeOk'。final ScaffoldState scaffold = Scaffold.maybeOk(context);”
  • @Miles Answerer 的意思可能是 maybeOf 而不是 maybeOk。看看他们的链接。
【解决方案2】:

经过大量的努力,我找到了一个成功的答案来消除这个错误。

如果您在 pubspec.yaml 中添加了 SVG 依赖项,那么您已将其替换为

flutter_svg: ^0.20.0-nullsafety.3

【讨论】:

    【解决方案3】:

    如果您使用的是 neumorphic

    定位,

    home/.pub-cache/hosted/pub.dartlang.org/flutter_neumorphic-3.0.3/lib/src/widget/app_bar.dart

    搜索,

    最终的 ScaffoldState 脚手架 = Scaffold.maybeOf(context);

    尝试使用, .maybeOf(context); 而不是 .of(context, nullOk: true);

    【讨论】:

      【解决方案4】:

      对于这里的任何人来说,对我有用的只是更新我的依赖项,然后运行flutter clean

      【讨论】:

        【解决方案5】:

        终于解决了。

        修改media_query.dart文件,搜索:static MediaQueryData of(BuildContext context)函数,修改为:

        static MediaQueryData of(BuildContext context, { bool nullOk = false })
        

        【讨论】:

          【解决方案6】:

          我终于设法解决了我的问题。对于我的情况,这不可能是你的,我删除了“build”文件夹,然后不做任何事情就运行它。然后flutter自动再次创建了文件。我个人在 Android Studio 上找不到“构建”。所以我在显示文件夹的 VSCode 上运行它。所以试试吧。

          【讨论】:

            【解决方案7】:
            • 首先,打开您的 pubspec.yaml 文件。

            • 点击右上角的Pub outdated菜单。如果正在使用 android studio IDE。

            几秒钟后,您将看到带有版本号包名称列表。

            • 使用最新版本号更新所有依赖项。此外,您还必须更新 dev_dependencies 下的 flutter_launcher_icons 版本。

            • 点击,Pub 获取更新菜单。

            成功获取所有包后。 运行您的应用。

            不过,您可能在旧的使用代码中存在一些错误。 例如,使用:

             Scaffold.of(context) 
            

            而不是

             Scaffold.of(context, nullOk: true)
            

            因为 nullOk 参数已作为迁移后的一部分被删除。

            注意:请参阅正确的使用文档。 https://api.flutter.dev/flutter/material/Scaffold/of.html

            再次运行您的项目并享受愉快的编码。谢谢

            【讨论】:

              【解决方案8】:

              将 :/Flutter/.pub-cache 文件夹移动到另一个地方对我有用。我没有删除,因为它可能会影响其他项目。那我再把它放回去。

              【讨论】:

                【解决方案9】:

                我遇到了类似的问题,发现在这种情况下它是依赖项的问题: flutter_neumorphic 神经拟态

                您可以将它们升级到符合 null-safety 的版本,或者您可以运行:flutter clean,以防两个依赖项都是最新的。

                【讨论】:

                  【解决方案10】:

                  我通过使用修复了这个问题

                  Scaffold.of(context)
                  

                  代替

                  Scaffold.of(context, nullOk: true)
                  

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 2021-04-26
                    • 2021-01-05
                    • 2020-01-03
                    • 2021-04-26
                    • 2021-10-06
                    • 1970-01-01
                    • 1970-01-01
                    • 2021-06-18
                    相关资源
                    最近更新 更多