'No named parameter with the name 'nullOk' error in flutter

After having horrible problems I finished by passing my project into another one. But now It gives me this error after trying to run my program. Which I never see before. And also, I didn't edit these codes because they are libraries.

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

Here's my 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

What should I do? If you need more details, just ask me.



Solution 1:[1]

Several nullOk parameters have been removed as part of null safety post-migration. You can read more on the corresponding design doc and its upcoming migration guide.

TL;DR you can try to use .maybeOf(context) instead of .of(context, nullOk: true);

You may have to update your dependencies to make it work.

Solution 2:[2]

After lots of effort, I found a successful answer to remove this error.

If you have added SVG dependency in pubspec.yaml so you have replaced this to

flutter_svg: ^0.20.0-nullsafety.3

Solution 3:[3]

If you are using neumorphic ,

Locate,

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

Search For,

final ScaffoldState scaffold = Scaffold.maybeOf(context);

try to use, .maybeOf(context); instead of .of(context, nullOk: true);

Solution 4:[4]

For anyone here, what worked for me was just to update my dependencies and then run flutter clean

Solution 5:[5]

Finally, Solved.

Alter the media_query.dart file, search for : static MediaQueryData of(BuildContext context) function, then modify it to :

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

Solution 6:[6]

  • First, open your pubspec.yaml file.

  • Click Pub outdated menu at the top right corner. If are using android studio IDE.

After a couple of seconds later you will see a list of the package names with version numbers.

  • Update all dependencies with the latest version number. Also, you have to update flutter_launcher_icons version under dev_dependencies as well.

  • Click, Pub get the menu for update.

After successful getting all packages. Run your App.

Still, you may have some errors in older uses codes. For example, use:

 Scaffold.of(context) 

instead of

 Scaffold.of(context, nullOk: true)

Because for null safety nullOk parameters have been removed as part of post-migration.

Note: See proper documentation of uses. https://api.flutter.dev/flutter/material/Scaffold/of.html

Again Run your project and enjoy happy coding. Thanks

Solution 7:[7]

Moving :/Flutter/.pub-cache folder to another place worked for me. I did not delete because it affects other projects maybe. Then I will put it its place again.

Solution 8:[8]

i had a similar problem and found that it was an issue with the dependencies in this case its: flutter_neumorphic neumorphic

you can upgrade them to versions that are null-safety compliant or you can run: flutter clean, incase both dependencies are up to date.

Solution 9:[9]

i Fixed this problem by using

Scaffold.of(context)

Instead of

Scaffold.of(context, nullOk: true)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 HandyPawan
Solution 3 ijas
Solution 4 Sébastien B
Solution 5 Asmoun
Solution 6 Subarata Talukder
Solution 7 Kas?m Onuk
Solution 8 Wilson Anyonga
Solution 9 Tharindu Nilakshana