Build: NoSuchMethodError: The method 'where' was called on null.

Created on 21 Feb 2020  Â·  3Comments  Â·  Source: dart-lang/build

Hi there,
I am getting the following error printed out for every file in my project when running flutter pub run build_runner build (same with watch).

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] json_serializable:json_serializable on lib/framework/service_connector.dart (cached):

I am using the freezed and json_serializable code generator plugins.

Dart SDK Version: 2.8.0-dev.5.0
Flutter Version: 1.14.6
build_runner Version: 1.7.4
OS: Windows

Most helpful comment

Nevermind, seems like an incorrect import statement in the form of import 'file://... after moving a file was causing this error. Fixed it by changing the import into a package import.

All 3 comments

Nevermind, seems like an incorrect import statement in the form of import 'file://... after moving a file was causing this error. Fixed it by changing the import into a package import.

I also made this error and have corrected it by removing all import 'file:///... references - however I still get this error after I have cleared caches and verified that no file contains any file:/// references. Any ideas how I can trouble shoot this?

clearing caches:

flutter clean
flutter pub get
flutter pub run build_runner clean

running builder:

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

output:

[SEVERE] auto_route_generator:autoRouteGenerator on lib/ui/widgets_smart/drawer_settings.dart:

Unsupported operation: Cannot resolve file:///Users/zzz/Documents/flutter/xxx/yyy/loading_fullscreen.dart; only "package" and "asset" schemes supported
[SEVERE] auto_route_generator:autoRouteGenerator on lib/ui/widgets_smart/sign_out_viewmodel.dart:

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] auto_route_generator:autoRouteGenerator on lib/ui/widgets_smart/drawer_search.dart:

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] auto_route_generator:autoRouteGenerator on lib/ui/widgets_smart/buttons/button_general.dart:

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] auto_route_generator:autoRouteGenerator on lib/ui/widgets_smart/buttons/button_share.dart:

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)

The error NoSuchMethodError: The method 'where' was called on null. happens to every generator, of which there are three - auto_route_generator, injectable_generator and json_serializable.

Any ideas where I go next to troubleshoot this?

Using build_runner: ^1.10.1


flutter doctor

[✓] Flutter (Channel stable, 1.20.2, on Mac OS X 10.15.6 19G73, locale en-GB)
    • Flutter version 1.20.2 at /Applications/flutter
    • Framework revision bbfbf1770c (4 days ago), 2020-08-13 08:33:09 -0700
    • Engine revision 9d5b21729f
    • Dart version 2.9.1


[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/alexblack/Library/Android/sdk
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.6, Build version 11E708
    • CocoaPods version 1.9.3

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 42.1.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.48.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.9.1

[✓] Connected device (1 available)
    • iPhone 11 Pro (mobile) • 5360F0EC-F786-4B67-8ADC-E5A9F2702329 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-6 (simulator)

Looks like I needed to close VSCode as it wasn't saving the files correctly??? Ran build_runner from a vanilla terminal and it worked

Was this page helpful?
0 / 5 - 0 ratings