mobxjs / mobx.dart

MobX for the Dart language. Hassle-free, reactive state-management for your Dart and Flutter apps.
https://mobx.netlify.app
MIT License
2.39k stars 311 forks source link

[BUG] mobx won't generate types generated by other generators, and always putting InvalidType in place of the correct type. #926

Closed andrelrf1 closed 10 months ago

andrelrf1 commented 1 year ago

I started to make a desktop flutter application that needs to access data from a sqlite database with drift, but while doing state management with mobx I realized that the type generated by drift was never recognized by mobx, where instead of the correct type was placed InvalidType. This can be fixed manually, just by replacing the type in the generated file, but as the application grows it is becoming unfeasible to make these changes, because every time we run build_runner the automatically generated files are updated and all changes made manually are lost. Is there any solution to this?

Heatclift commented 1 year ago

Same issue here, on our case, it puts "InvalidType" instead of "AppLifecycleState" or "Size".

amondnet commented 1 year ago

https://github.com/dart-lang/build/issues/2701

ulisseshen commented 1 year ago

Same issue here, with type AppLocalizations from the package I10n import 'package:flutter_gen/gen_l10n/app_localizations.dart';

amondnet commented 1 year ago

@andrelrf1 @ulisseshen @Heatclift

This is not a bug in mobx, but depending on your code, build_runner may not work. In my experience, I've had no problems using the libraries mentioned above. I can't help you without reproducible source code.

See below to help you resolve the issue.

https://github.com/dart-lang/build/blob/master/build_config/README.md#adjusting-builder-ordering https://github.com/dart-lang/build/issues/2701 https://github.com/trevorwang/retrofit.dart/issues/578

TobiasPrt commented 11 months ago

For anyone coming across this issue who does not get the - relatively sparse - docs about adjusting the build order, add this to your build.yaml file:

global_options:
  json_serializable:json_serializable:
    runs_before:
      - mobx_codegen:mobx_generator

Replace the reference to json_serialization with the package and builder you are using.

amondnet commented 10 months ago

@ulisseshen https://github.com/FlutterGen/flutter_gen/blob/main/packages/runner/build.yaml

global_options:
  flutter_gen_runner:
    runs_before:
      - mobx_codegen:mobx_generator
andrelrf1 commented 8 months ago

Thanks guys, this really worked! Sorry for the delay in responding.

pavanpodila commented 8 months ago

I think we should make a guide for this on the website...can you please make a short PR for this ? 💯