Error: No named parameter with the name 'nullOk'. after updating to FLutter 2.0

1,585

This is due to the version of Flutter you're using (stable channel, Flutter 2.0.3) is null-safety enabled. These are the APIs that were subject to change & so you need to use this migration guide to modify your code to use the new form of the APIs with null safety.

Method 1:

Check if you're using any of the aforementioned API dependencies & use .maybeOf(context) instead of .of(context, nullOk: true);

In your posted code,change your Localizations.localeOf(context, nullOk: true); to Localizations.maybeLocaleOf(context);

Method 2:

Find the dependency that caused the problem & update it to null safety, for example, if you're using flutter_svg: ^0.19.0 you'll encounter the same error, so either update it to flutter_svg: ^0.20.0-nullsafety.3 or in case you can't migrate to null safety yet, use this version flutter_svg: ^0.19.3

Method 3:

Alternatively, if you can also downgrade your Flutter version which doesn't provide null safety. It should also fix the error but needs the downgrading. To downgrade to v1.22.6 run the following command:

flutter downgrade v1.22.6

After each/any method, run the following commands:

flutter clean
flutter pub get
flutter run
Share:
1,585
Anmol Sahu
Author by

Anmol Sahu

Updated on December 28, 2022

Comments

  • Anmol Sahu
    Anmol Sahu over 1 year

    I updated my App to the latest version of the Flutter. E:\anmol\Jan' 2021 -Backup\nemar_user_(for_new_packages)>flutter --version Flutter 2.0.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision 4d7946a68d (3 days ago) • 2021-03-18 17:24:33 -0700 Engine • revision 3459eb2436 Tools • Dart 2.12.2

    Along with that, I upgraded new packages in pubspec.yaml When I run my app, then it shows the following errors, I tried so many things but nothing Works. Any Kind of Help would be appreciated.

    /E:/flutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/expandable_text-1.3.2/lib/expandable_text.dart:153:56: Error: No named parameter with the name 'nullOk'. final locale = Localizations.localeOf(context, nullOk: true); ^^^^^^ /E:/flutterSDK/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: Context: Found this candidate, but the arguments don't match. static Locale localeOf(BuildContext context) { ^^^^^^^^

    FAILURE: Build failed with an exception.

    • Where: Script 'E:\flutterSDK\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991

    • What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.

    Process 'command 'E:\flutterSDK\flutter\bin\flutter.bat'' finished with non-zero exit value 1

    • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

    • Get more help at https://help.gradle.org

    BUILD FAILED in 46s Exception: Gradle task assembleDebug failed with exit code 1