I'm attempting to generate MobX .g files in my Flutter project using the flutter pub run build_runner build
but I am getting these errors I tried many available solutions but am still getting these:
Bad state: Unexpected diagnostics:
/Users/macbook/Documents/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:89:1 - Can't have modifier 'final' here.
[SEVERE] json_serializable:json_serializable on lib/store/backend/lesson_flow/interaction_switcher_store.dart:
Bad state: Unexpected diagnostics:
/Users/macbook/Documents/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:89:1 - Can't have modifier 'final' here.
[SEVERE] json_serializable:json_serializable on lib/store/progress_bar_play_status.dart:
Bad state: Unexpected diagnostics:
/Users/macbook/Documents/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:89:1 - Can't have modifier 'final' here.
[SEVERE] json_serializable:json_serializable on lib/store/login_store.dart:
Bad state: Unexpected diagnostics:
/Users/macbook/Documents/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:89:1 - Can't have modifier 'final' here.
[SEVERE] json_serializable:json_serializable on lib/store/backend_store.dart:
Bad state: Unexpected diagnostics:
/Users/macbook/Documents/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:89:1 - Can't have modifier 'final' here.
[SEVERE] mobx_codegen:mobx_generator on lib/course/course.dart:
Bad state: Unexpected diagnostics:
/Users/macbook/Documents/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:89:1 - Can't have modifier 'final' here.
[SEVERE] mobx_codegen:mobx_generator on lib/firebase_options.dart:
Bad state: Unexpected diagnostics:
/Users/macbook/Documents/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:89:1 - Can't have modifier 'final' here.
[SEVERE] mobx_codegen:mobx_generator on lib/repositories/topbar_state_repositories.dart:
Bad state: Unexpected diagnostics:
/Users/macbook/Documents/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:89:1 - Can't have modifier 'final' here.
[SEVERE] mobx_codegen:mobx_generator on lib/repositories/completed_lessons_repository.dart:
Bad state: Unexpected diagnostics:
/Users/macbook/Documents/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:89:1 - Can't have modifier 'final' here.
[SEVERE] mobx_codegen:mobx_generator on lib/models/lesson_pop_and_show_container_media.dart:
Bad state: Unexpected diagnostics:
/Users/macbook/Documents/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:89:1 - Can't have modifier 'final' here.
[SEVERE] mobx_codegen:mobx_generator on lib/models/index.dart:
Bad state: Unexpected diagnostics:
/Users/macbook/Documents/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:89:1 - Can't have modifier 'final' here.
[SEVERE] mobx_codegen:mobx_generator on lib/models/lesson_video_subtitle.dart:
Bad state: Unexpected diagnostics:
/Users/macbook/Documents/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:89:1 - Can't have modifier 'final' here.
[SEVERE] mobx_codegen:mobx_generator on lib/models/lesson_interaction_button_config.dart:
Bad state: Unexpected diagnostics:
/Users/macbook/Documents/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:89:1 - Can't have modifier 'final' here.
[SEVERE] mobx_codegen:mobx_generator on lib/models/lesson_segment.dart:
here is my pubspec.yaml
:
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_svg: ^0.22.0
video_player: ^2.1.12
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.3
percent_indicator: ^3.0.1
cached_network_image: ^3.1.0
flutter_mobx: ^2.0.2
animated_text_kit: ^4.2.1
carousel_slider: ^4.0.0
smooth_page_indicator:
git:
url: https://github.com/rzakirov/smooth_page_indicator.git
ref: baba9840312a78b9f3c60320920169aec00cb10d
darq: ^1.1.1
flutter_markdown: ^0.6.4
rounded_loading_button: ^2.0.5
lottie: ^1.2.2
json_serializable: ^4.1.4
quiver: ^3.0.1
retry: ^3.1.0
collection:
get: ^4.3.8
mask_text_input_formatter: ^2.0.0
store_redirect: ^2.0.0
shared_preferences: 2.0.7
pinch_zoom: ^1.0.0
url_launcher: ^6.0.10
flutter_screenutil: ^5.0.1
path_provider: ^2.0.8
firebase_remote_config: ^3.0.4
flutter_isolate: ^2.0.0
firebase_storage: 11.0.3
firebase_crashlytics: ^3.0.4
firebase_analytics: ^10.0.4
firebase_app_check: ^0.1.1+3
firebase_core: ^2.17.0
cloud_firestore: ^4.9.3
firebase_auth: ^4.10.1
dependency_overrides:
plugin_platform_interface: ^2.1.8
dev_dependencies:
flutter_test:
sdk: flutter
flutter_launcher_icons: ^0.9.1
lint: ^1.0.0
mobx_codegen: ^2.0.2
build_runner: ^2.1.11
Attempted Solutions
I've tried the following solutions without success:
analyzer
in dependency_overridesHow do we solve the problem?
Remove the json_serializable
from dependencies section and add in the dev_dependencies and change the versions of json_serializable
& build_runner
It sould solve your problem.
dev_dependencies:
flutter_test:
sdk: flutter
flutter_launcher_icons: ^0.9.1
json_serializable: ^6.7.1
build_runner: ^2.4.6
mobx_codegen: ^2.0.2
lint: ^1.0.0