颤振中没有名为“ nullOk”的命名参数错误

时间:2020-11-11 17:14:53

标签: flutter dart

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

../../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

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

8 个答案:

答案 0 :(得分:5)

如果您使用 neumorphic

定位,

<块引用>

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

搜索,

<块引用>

最终 ScaffoldState scaffold = Scaffold.maybeOf(context);

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

答案 1 :(得分:3)

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

答案 2 :(得分:1)

最后解决了。

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

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

答案 3 :(得分:1)

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

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

flutter_svg:^0.20.0-nullsafety.3

答案 4 :(得分:0)

几个nullOk参数已作为null安全迁移后的一部分被删除。您可以在corresponding design doc及其即将推出的migration guide上阅读更多内容。

TL; DR,您可以尝试使用.maybeOf(context)代替.of(context, nullOk: true);

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

答案 5 :(得分:0)

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

答案 6 :(得分:0)

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

答案 7 :(得分:0)

我遇到了类似的问题,发现在这种情况下是依赖关系的问题: flutter_neumorphic 仿形

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