Sanakhatun Shaikh
Sanakhatun Shaikh

Reputation: 2339

Error: Method not found: 'NullThrownError' in flutter

I was getting the below error while running the flutter application post flutter upgrade to 3.10.6

Failed to build build_runner:build_runner:
/C:/Users/Admin/AppData/Local/Pub/Cache/hosted/pub.dev/build_runner-2.3.2/lib/src/build_script_generate/bootstrap.dart:76:40: Error: Method not found: 'NullThrownE
rror'.
      final error = e[0] as Object? ?? NullThrownError();
                                       ^^^^^^^^^^^^^^^

Upvotes: 8

Views: 5281

Answers (7)

Compaq LE2202x
Compaq LE2202x

Reputation: 2376

This is what worked for me as I'm having Dart project:

dart pub upgrade

But if your project is Flutter, run this:

flutter pub upgrade

Upvotes: 0

AlexBoy
AlexBoy

Reputation: 1

You can remove build_runner-(*any version or variant) package/s in .../AppData/Local/Pub/Cache/hosted/pub.dev

It works for me.

Upvotes: 0

Ali Mahfud
Ali Mahfud

Reputation: 303

For me this happen because the incompatibility of each package used. I think the packages that relate to build runner are floor_generator and retrofit_generator. You can simply resolve the issue by following these:

  • remove retrofit_generator, floor_generator and build_runner from dev_dependencies
  • add packages from terminal -> flutter pub add dev:build_runner, flutter pub add dev:floor_generator and flutter pub add dev:retrofit_generator
  • try to build the build_runner again -> dart run build_runner build

or if the error still occur try this package version:

  • dependencies: floor: ^1.4.2 retrofit: ^3.0.1
  • dev_dependencies: build_runner: ^2.4.6 retrofit_generator: ^4.2.0 floor_generator: ^1.4.2

Upvotes: 11

Zainul Paleri
Zainul Paleri

Reputation: 1

Try dependecy follwing version in you pubspec.yaml file

retrofit_generator: ^7.0.8 build_runner: ^2.1.0

Upvotes: 0

robin
robin

Reputation: 1

I use flutter3.10.5 version, and I also encountered the same error when using build_runner. Confusing enter image description here

Upvotes: 0

Vaygeth
Vaygeth

Reputation: 184

This what worked for me

  • delete pubspec.lock
  • flutter pub cache clean
  • flutter clean
  • flutter upgrade (probably optional)
  • flutter pub get
  • flutter pub run build_runner build --delete-conflicting-outputs

Upvotes: -1

Sanakhatun Shaikh
Sanakhatun Shaikh

Reputation: 2339

Resolved issue by upgrading build_runner dependency

Steps:

  1. Open Project in Android Studio

  2. Navigate to Terminal Tab in Android Studio

  3. Execute the below command

    $ flutter clean

    $ flutter pub get

    $ flutter pub upgrade

    $ flutter pub run build_runner build --delete-conflicting-outputs

  4. Run the application.

The above solution worked for me. Hope, it will help to others as well.

Upvotes: 4

Related Questions