Mobx.dart: NoSuchMethodError: The method 'where' was called on null.

Created on 25 Jan 2020  路  6Comments  路  Source: mobxjs/mobx.dart

Whenever I run build_runner, this is the output i get. FYI I also use Hive as the Caching library. It also has code generator. Except maybe 5 or 6 stores, other stores generated successfully

I tried the following options, but the problem still exists:
Flutter Clean
Flutter pub get & upgrade
build_runner delete conflicting outputs
build_runner clean
Invalidate caches and restart

C:\Users\hp\Documents\Majesty>flutter pub run build_runner watch
[INFO] Generating build script...
[INFO] Generating build script completed, took 470ms

[INFO] Setting up file watchers...
[INFO] Setting up file watchers completed, took 14ms

[INFO] Waiting for all file watchers to be ready...
[INFO] Waiting for all file watchers to be ready completed, took 150ms

[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 316ms

[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 7.9s

[INFO] Running build...
[INFO] Running build completed, took 103ms

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 205ms

[SEVERE] hive_generator:hive_generator on lib/main.dart (cached):

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

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/goals/widgets/goals_nutrition_widget.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/goals/widgets/goals_personal_widget.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/authenticate/login/login_form.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/authenticate/login/store/login_store.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/Utils/fluro_config/routes.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/authenticate/register/register_screen.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/onboarding/screens/onboarding_screen_two_metric.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/goals/widgets/goals_list_item.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/onboarding/screens/ob_calories_beginner.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/common_screens/menu_drawer/store/majesty_drawer_store.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/goals/widgets/goals_water_widget.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/common_screens/menu_drawer/majesty_drawer.dart (cached):

Unsupported operation: Cannot resolve file:///C:/Users/hp/Documents/Majesty/lib/src/meal_plan/main/meal_plan_screen.dart; only "package" and "asset" schemes supported
[SEVERE] hive_generator:hive_generator on lib/src/Utils/fluro_config/route_handlers.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/goals/widgets/goals_personal_widget.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/goals/goals_screen.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/goals/dialogs/goals_weight_dialog.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/goals/dialogs/goals_macros_dialog.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/onboarding/screens/ob_user_level.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/onboarding/screens/onboarding_screen_two_metric.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/goals/dialogs/goals_options_dialog.dart (cached):

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

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/goals/widgets/goals_nutrition_widget.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/common_screens/menu_drawer/majesty_drawer.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/onboarding/screens/ob_weight_beginner.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/authenticate/login/login_screen.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/search/search_screen.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/onboarding/screens/ob_weight_expert.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/goals/dialogs/goals_options_dialog.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/onboarding/screens/onboarding_screen_one.dart (cached):

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

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

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/goals/dialogs/goals_water_dialog.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/goals/widgets/goals_water_widget.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/onboarding/screens/ob_calories_expert.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/authenticate/register/store/register_store.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/goals/store/goals_store.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/diary/diary_screen.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/authenticate/register/register_screen.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/onboarding/screens/ob_weight_beginner.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/onboarding/screens/ob_body_fat_percentage.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/onboarding/store/onboarding_store.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/Utils/fluro_config/routes.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/goals/widgets/goals_list_item.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/goals/dialogs/goals_water_dialog.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/goals/dialogs/goals_weight_dialog.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/goals/store/goals_store.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/onboarding/screens/ob_diet_selection.dart (cached):

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

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

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/onboarding/screens/ob_body_fat_percentage.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/onboarding/screens/onboarding_screen_one.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/common_screens/menu_drawer/store/majesty_drawer_store.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/Utils/widgets/app_bars/majesty_appbar.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/goals/dialogs/goals_height_dialog.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/onboarding/screens/onboarding_screen_two_imperial.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/goals/dialogs/goals_macros_dialog.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/onboarding/screens/ob_weight_expert.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/foods_manager/foods_manager_screen.dart (cached):

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

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/onboarding/screens/ob_diet_selection.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/Utils/widgets/app_bars/majesty_appbar.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/goals/dialogs/goals_height_dialog.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/onboarding/on_boarding_screen.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/onboarding/screens/ob_macros.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/onboarding/screens/ob_calories_beginner.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/onboarding/screens/ob_calories_expert.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/authenticate/login/store/login_store.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/authenticate/login/login_form.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/onboarding/store/onboarding_store.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/onboarding/screens/ob_user_level.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/authenticate/login/login_screen.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/onboarding/screens/ob_macros.dart (cached):

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

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] hive_generator:hive_generator on lib/src/onboarding/screens/onboarding_screen_two_imperial.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/authenticate/register/store/register_store.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] mobx_codegen:mobx_generator on lib/src/Utils/fluro_config/route_handlers.dart (cached):

NoSuchMethodError: The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (AssetId) => bool)
[SEVERE] Failed after 399ms

Most helpful comment

Today I had the same problem. For me the cause was that I somehow had imported a file not with the package name, but with file://...
This was not even in a store file.
To solve it, I just removed the import and reimported it via the package name.

All 6 comments

Does it throw errors if you don't use hive ?

Ok I somehow solved the problem. I downgraded both the MobX and hive library to the versions when they were working smoothly. .I slowly started bumping versions of hive one by one and finally it started working.
I did the same for MobX. I started bumping MobX versions until there was no problem. Now everything works perfectly. One odd thing is, I still don't know what caused the NoSuchMethodError: The method 'where' was called on null error.

Glad to hear it got resolved. Sometimes it just could be a bad build artifact that could have been cached and not purged properly. Hard to pin point but clearing your .dart_tool could help

Today I had the same problem. For me the cause was that I somehow had imported a file not with the package name, but with file://...
This was not even in a store file.
To solve it, I just removed the import and reimported it via the package name.

I am getting this error as @MrCheese02 has described it, with the same cause (no idea how I managed to do a file import either). I have removed all reference to file:///... but am still getting the error. I have flutter clean, flutter pub cache repair and flutter pub run build_runner clean but still flutter pub run build_runner build --delete-conflicting-outputs responds with

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

Unsupported operation: Cannot resolve file:///Users/xxx/Documents/flutter/yyy/zzz/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)
[INFO] 55.3s elapsed, 22/38 actions completed.


etc, there's about 30 'where' errors.

drawer_settings.dart and all subsequent files it identifies definitely don't have any file:///... reference in it so it must be cached somewhere - but I have cleared all caches.

The file:/// imports can be caused by IntelliJ's refactoring function, it's very buggy and creates those imports when moving files.
(I too have this issue exactly as @FickleLife describes.)

Edit: turns out the dodgy import was actually in another package I'm developing, which was hard to work out. I eventually found the relevant file with grep -ar <import>.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dukaric1991 picture dukaric1991  路  5Comments

pavanpodila picture pavanpodila  路  5Comments

DeepStyles picture DeepStyles  路  6Comments

viktorszekeress picture viktorszekeress  路  4Comments

jiyarong picture jiyarong  路  4Comments