Stacked-Org/stacked

[bug]: stacked generate failed

Closed this issue · 5 comments

sjimy commented

Describe the bug

execute stacked generate output log

[SEVERE] mockito:mockBuilder on test/helpers/test_helpers.dart (cached):

Null check operator used on a null value

[SEVERE] Failed after 118ms

Command complete. ExitCode: 1

not found test_helpers.mocks.dart

image

image

To reproduce

execute stacked generate output log

Expected behavior

No response

Screenshots

No response

Additional Context

No response

Hi @sjimy , seems that you have an error on the code and for that reason the test_helpers.mocks.dart could not be generated. Fix that issue and run generate again.

Error
Null check operator used on a null value.

You can run flutter analyze to determine where is the issue.

Having the same issue. Ran flutter analyze and I don't have any errors in code (just a few infos). The only errors reported by analyze are:

  error • Undefined class 'MockNavigationService' • test/helpers/test_helpers.dart:28:1 • undefined_class
  error • The function 'MockNavigationService' isn't defined • test/helpers/test_helpers.dart:30:19 • undefined_function
  error • Undefined class 'MockBottomSheetService' • test/helpers/test_helpers.dart:35:1 • undefined_class
  error • The function 'MockBottomSheetService' isn't defined • test/helpers/test_helpers.dart:39:19 • undefined_function
  error • Undefined class 'MockDialogService' • test/helpers/test_helpers.dart:70:1 • undefined_class
  error • The function 'MockDialogService' isn't defined • test/helpers/test_helpers.dart:72:19 • undefined_function
  error • Undefined class 'MockThemeService' • test/helpers/test_helpers.dart:77:1 • undefined_class
  error • The function 'MockThemeService' isn't defined • test/helpers/test_helpers.dart:79:19 • undefined_function
  error • Undefined class 'MockAuthenticationService' • test/helpers/test_helpers.dart:84:1 • undefined_class
  error • The function 'MockAuthenticationService' isn't defined • test/helpers/test_helpers.dart:86:19 • undefined_function

I also tried creating a new project with the cli, and there's this errors out of the box. So my guess is that the issue is with Stacked generated code 😕

Commenting out this two Stacked services fixes the issue:

  // getAndRegisterBottomSheetService();
  // getAndRegisterDialogService();

This is mostly because both services use bang operators (!) internally, and seems like one (or many) are causing issues with Mockito.

Hi @mradzinski, how are you? Which version of Stacked CLI are you using?

I just created a project from scratch without any issue. Below is my development environment and the output of the execution.

Stacked CLI v1.11.1

Flutter Doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.4.1 22F770820d darwin-x64, locale es-419)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.81.0)
[✓] Connected device (2 available)
[✓] Network resources

• No issues found!
{▸} stacked create app i986
No configuration file found. Default Stacked values will be used.
Running flutter create i986 -e ...
Creating project i986...

Resolving dependencies in i986...


Got dependencies in i986.

Wrote 128 files.


All done!

You can find general documentation for Flutter at: https://docs.flutter.dev/
Detailed API documentation is available at: https://api.flutter.dev/
If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev

In order to run your empty application, type:

  $ cd i986
  $ flutter run

Your empty application code is in i986/lib/main.dart.


Command complete. ExitCode: 0
Add Stacked Magic ...
Created File: 'i986/test/viewmodels/notice_sheet_model_test.dart'
Created File: 'i986/test/viewmodels/info_alert_dialog_model_test.dart'
Created File: 'i986/test/viewmodels/home_viewmodel_test.dart'
Created File: 'i986/test/helpers/test_helpers.dart'
Created File: 'i986/stacked.json'
Created File: 'i986/pubspec.yaml'
Created File: 'i986/lib/ui/views/startup/startup_viewmodel.dart'
Created File: 'i986/lib/ui/views/startup/startup_view.dart'
Created File: 'i986/lib/ui/views/home/home_viewmodel.dart'
Created File: 'i986/lib/ui/views/home/home_view.dart'
Created File: 'i986/lib/ui/dialogs/info_alert/info_alert_dialog_model.dart'
Created File: 'i986/lib/ui/dialogs/info_alert/info_alert_dialog.dart'
Created File: 'i986/lib/ui/common/ui_helpers.dart'
Created File: 'i986/lib/ui/common/app_strings.dart'
Created File: 'i986/lib/ui/common/app_colors.dart'
Created File: 'i986/lib/ui/bottom_sheets/notice/notice_sheet_model.dart'
Created File: 'i986/lib/ui/bottom_sheets/notice/notice_sheet.dart'
Created File: 'i986/lib/main.dart'
Created File: 'i986/lib/app/app.dart'
Created File: 'i986/README.md'
Created File: 'i986/.vscode/settings.json'
Running dart format . -l 80 in i986/...
Formatted lib/app/app.dart

Formatted lib/main.dart

Formatted lib/ui/bottom_sheets/notice/notice_sheet.dart

Formatted lib/ui/bottom_sheets/notice/notice_sheet_model.dart

Formatted lib/ui/common/app_colors.dart

Formatted lib/ui/common/app_strings.dart

Formatted lib/ui/common/ui_helpers.dart

Formatted lib/ui/dialogs/info_alert/info_alert_dialog.dart

Formatted lib/ui/dialogs/info_alert/info_alert_dialog_model.dart

Formatted lib/ui/views/home/home_view.dart

Formatted lib/ui/views/home/home_viewmodel.dart

Formatted lib/ui/views/startup/startup_view.dart

Formatted lib/ui/views/startup/startup_viewmodel.dart

Formatted test/helpers/test_helpers.dart

Formatted test/viewmodels/home_viewmodel_test.dart

Formatted test/viewmodels/info_alert_dialog_model_test.dart

Formatted test/viewmodels/notice_sheet_model_test.dart

Formatted 17 files (17 changed) in 0.41 seconds.

Command complete. ExitCode: 0
Running flutter pub get in i986/...
Resolving dependencies...


+ _fe_analyzer_shared 61.0.0 (63.0.0 available)
+ analyzer 5.13.0 (6.1.0 available)
+ args 2.4.2
+ build 2.4.1
+ build_config 1.1.1
+ build_daemon 4.0.0
+ build_resolvers 2.2.1
+ build_runner 2.4.6
+ build_runner_core 7.2.10
+ built_collection 5.1.1
+ built_value 8.6.1
+ checked_yaml 2.0.3
+ code_builder 4.5.0
  collection 1.17.1 (1.18.0 available)
+ convert 3.1.1
+ crypto 3.0.3
+ dart_style 2.3.2
+ file 7.0.0
+ fixnum 1.1.0
+ freezed_annotation 2.4.1
+ frontend_server_client 3.2.0
+ get 4.6.5
+ get_it 7.6.0
+ glob 2.1.2
+ graphs 2.3.1
+ http_multi_server 3.2.1
+ http_parser 4.0.2
+ io 1.0.4
+ json_annotation 4.8.1
+ logger 1.4.0 (2.0.1 available)

+ logging 1.2.0
  matcher 0.12.15 (0.12.16 available)
  material_color_utilities 0.2.0 (0.8.0 available)
+ mime 1.0.4
+ mockito 5.4.2
+ nested 1.0.0
+ package_config 2.1.0
+ pool 1.5.1
+ provider 6.0.5
+ pub_semver 2.1.4
+ pubspec_parse 1.2.3
+ recase 4.1.0
+ shelf 1.4.1
+ shelf_web_socket 1.0.4
+ source_gen 1.4.0
  source_span 1.9.1 (1.10.0 available)
  stack_trace 1.11.0 (1.11.1 available)
+ stacked 3.4.1
+ stacked_generator 1.5.0
+ stacked_services 1.3.0
+ stacked_shared 1.4.0
  stream_channel 2.1.1 (2.1.2 available)
+ stream_transform 2.1.0
  test_api 0.5.1 (0.6.1 available)
+ timing 1.0.1
+ typed_data 1.3.2

+ universal_io 2.2.2
+ watcher 1.1.0
+ web_socket_channel 2.4.0
+ yaml 3.1.2

Changed 53 dependencies!

Command complete. ExitCode: 0
Running dart run build_runner build --delete-conflicting-outputs in i986/...
[INFO] Generating build script...

[INFO] Generating build script completed, took 427ms


[INFO] Precompiling build script......

[INFO] Precompiling build script... completed, took 7.9s


[INFO] Initializing inputs

[INFO] Building new asset graph...

[INFO] Building new asset graph completed, took 830ms

[INFO] Checking for unexpected pre-existing outputs....

[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms


[INFO] Running build...

[INFO] Generating SDK summary...

[INFO] 2.5s elapsed, 0/16 actions completed.

[INFO] 4.4s elapsed, 0/16 actions completed.

[INFO] Generating SDK summary completed, took 5.1s


[INFO] 6.2s elapsed, 15/17 actions completed.

[INFO] 7.2s elapsed, 15/17 actions completed.

[INFO] 8.2s elapsed, 15/17 actions completed.

[INFO] 16.5s elapsed, 15/17 actions completed.

[INFO] 17.5s elapsed, 90/91 actions completed.

[INFO] Running build completed, took 18.2s

[INFO] Caching finalized dependency graph...

[INFO] Caching finalized dependency graph completed, took 47ms


[INFO] Succeeded after 18.3s with 5 outputs (115 actions)


Command complete. ExitCode: 0
Running dart format . -l 80 in i986/...
Formatted 22 files (0 changed) in 0.47 seconds.

Command complete. ExitCode: 0
Cleaning project...
Project cleaned.
{▸} flutter analyze
Analyzing i986...
No issues found! (ran in 1.4s)
{▸} flutter test
00:12 +2: All tests passed!

i observed same behaviour, but after runing following comand manually
flutter pub run build_runner build --delete-conflicting-outputs
helped get rid of error, but i dont know the reason

Same issue with cli 1.13.1 — remedied by running

dart run build_runner clean
dart run build_runner --delete-conflicting-outputs