-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[build_runner] Reports 'Invalid Type' for VoidCallback in Freezed Classes and MobX Stores, as well as for Color Type in MobX Stores #3596
Comments
@GhaithMalas99 can you run with |
Note also that when running on a flutter package, you must use the You should be able to either do |
@mrRedSun it looks like that build succeeded because it didn't do anything at all :) I still can't proceed with diagnosing this issue until I get a stack trace of the error |
@mrRedSun Can you link similar logs but for one of the failed builds? |
That's the thing, those are the logs I get when my types turn to InvaidType inside generated files |
Oh see, so it is running fine but producing bad code. Does this reproduce with a basic flutter project using freezed? |
I tried just creating a minimal project using freezed and that doesn't repro it. Would it be possible for you to try and create a minimal repro, possibly using mobx and freezed together in such a way that triggers this? |
@jakemac53 I'll try tomorrow, in meantime please check if you are running build on top of already generated files without clean, that's the part that's not working it seems |
@jakemac53 I was unable to create a minimal reproduction project, unfortunately, even with the same pubspec it seems to be working |
@GhaithMalas99 in case you need a workaround |
BriefI encountered the same issue, which turned out to be caused by MobX files being generated before the classes they depended on, leading to "InvalidType" replacements (in my case). I'm using Solution №1targets:
$default:
sources:
- lib/**
- pubspec.*
- $package$
- graphql/**
builders:
json_serializable:
options:
explicit_to_json: true
graphql_codegen:
options:
outputDirectory: /lib/__generated/graphql
assetsPath: graphql/**
clients:
- graphql_flutter
global_options: # <-- solution
graphql_codegen:
runs_before:
- mobx_codegen:mobx_generator Thanks to this issue: mobxjs/mobx.dart#926. Solution №2targets:
$default:
sources:
- lib/**
- pubspec.*
- $package$
- graphql/**
builders:
json_serializable:
options:
explicit_to_json: true
graphql_codegen:
options:
outputDirectory: /lib/__generated/graphql
assetsPath: graphql/**
clients:
- graphql_flutter
builders:
mobx_generator:
target: ':store_generator'
import: 'package:mobx_codegen/builder.dart'
builder_factories: [ 'storeGenerator' ]
build_extensions: { '.dart': [ '.store.g.part' ] }
auto_apply: dependents
build_to: cache
applies_builders: [ 'source_gen|combining_builder' ]
required_inputs: [ '.graphql.dart' ] # <-- solution Key points:
Here is a similar issue discussed on GitHub, which suggested a described solution with |
Any updates on this? |
Adding following to my
|
When using [Freezed/MobX] to generate code for my Dart classes in a Flutter project, I encountered an issue where the build runner reports "invalid type" for certain fields or properties in my classes.
Affected Types:
VoidCallback Type: In my Flutter project, I have classes that include fields or properties of type VoidCallback, which represent functions that take no arguments and return no value. The build runner is encountering difficulties when dealing with these types.
Color Type: I'm also experiencing issues with fields or properties of the Color type from the dart:ui library in my MobX stores or models. The build runner is flagging them as "invalid types."
Both VoidCallback types and Color types in MobX stores and Freezed classes result in 'InvalidType' errors after running build_runner. Additionally, when utilizing some Freezed-generated classes within MobX stores, the same 'InvalidType' issues persist.
Expected Behavior:
I expect the build runner to handle these types correctly and generate code without reporting "invalid type" errors.
Environment:
Flutter Version: 3.13.7 • channel stable
Dart Version: 3.1.3
freezed:2.4.5
mobx_codegen: ^2.4.0
build_runner: ^2.4.6
Please let me know if additional information or code samples are needed to investigate and address this issue. Any guidance on how to work around this problem temporarily would also be appreciated.
The text was updated successfully, but these errors were encountered: