Closed point-source closed 6 months ago
This also is happening on any fields with the type Offset
rather than Color
Strange, I cannot reproduce that. Whats your build_runner version?
Pubspec.yaml:
environment:
sdk: ">=3.0.6 <4.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
uuid: ^3.0.6
collection: ^1.17.1
dart_mappable: ^4.0.1
flutter_riverpod: ^2.3.6
riverpod_annotation: ^2.1.1
fast_immutable_collections: ^9.1.5
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
dart_mappable_builder: ^4.0.1
build_runner: ^2.4.6
riverpod_generator: ^2.2.3
custom_lint: ^0.5.3
riverpod_lint: ^2.1.0
Versions from my pubspec.lock:
build_runner: 2.4.6
build: 2.4.1
collection: 1.17.2
meta: 1.9.1
type_plus: 2.1.0
analyzer: 6.2.0
source_gen: 1.4.0
Strangely, I also have this happening on an older and larger project which is still on dart_mappable 3.1.1. Wondering if maybe it's possible for my sdk to be corrupt? What else could this be?
It is apparent to me that it has something todo with dart:ui
being sometimes not resolved by the analyzer, therefore types from it like Color or Offset are not resolved. But I still don't know how to reproduce it.
Happy to set up a meeting / screen share or something if you want to dig through. I will try to get an example repo going as well.
I've managed to make what should be a very minimal reproduction of it. If I follow the steps in the readme, I get invalidtype while generating files with this repo: https://github.com/point-source/mappable_invalid_type
I figured it out. It's the difference between using flutter pub run
and dart run
to run the build_runner. While this makes sense to me, the reason I was using dart run
is because when you use flutter pub run
, it outputs this deprecation warning: Deprecated. Use 'dart run' instead.
So either there should be way for analysis to detect Color
and Offset
, etc while using the dart run
command or there is something about dart run
that doesn't fully replace flutter pub run
and this is either a bug or a breaking change.
Current workaround is to use the deprecated flutter pub run
method.
EDIT: Related but did not fix: https://stackoverflow.com/questions/76545047/flutter-pub-run-build-runner-build-is-deprecated
EDIT 2: Turns out this is because I have both dart and flutter installed on my machine because sometimes I write native dart (non-flutter) apps. So while the flutter sdk contained a dart binary, my default dart binary was the standalone (and often more up-to-date) version. This apparently means it cannot identify flutter-specific types. If I use the dart binary included in the flutter sdk, then this works.
Is the flutter team modifying the version of dart that gets packaged with flutter? Does dart 3.2.3 standalone =/= dart 3.2.3 bundled?
I wonder what the "correct" way is to use both flutter and the latest native dart on the same machine. :/
And now, after having had it working successfully for several days, it is suddenly doing it again even though I'm using the correct binary. This is a really pesky bug. It's only occurring on one of my projects now instead of all of them. So I'm thinking this may be a compound issue.
Thanks for all your investigations. This all looks like its something with the dart/flutter setup and less something I "fix" on the package side.
One thing I might be able todo is to catch any "InvalidType" and just use the ast name instead of relying on the analyzer to resolve it. That could potentially circumvent the problem entirely. But no promises as I haven't tested if this actually works.
I agree. The only reason I didn't close this is because of the off-chance that you wanted to try to workaround or warn/alert when this misconfiguration is detected. But ultimately, this isn't a library issue. At least it's documented here now.
As for it returning, this seemed to have something to do with a VSCode cache issue. I have now resolved it again. So I'm back to operational. Thanks for the ongoing support. Feel free to close or leave open if you want to do anything with this. Your call. Thanks
I'm probably going to delete the PoC repo though if that's alright with you.
I have this class:
Here is the generated output:
Noticed that these lines contain "InvalidType":
Even though I don't believe this affects the code generation step, my main method looks like this:
And here is the color mapper:
Fwiw, this looks very similar to issue #102
Things I've tried:
flutter clean
, fetching deps, re-buildingbuild
and.dart_tool
directories, fetching daps, and re-buildingVersion info: Flutter 3.13.8 • channel stable • https://github.com/flutter/flutter.git Framework • revision 6c4930c4ac (6 days ago) • 2023-10-18 10:57:55 -0500 Engine • revision 767d8c75e8 Tools • Dart 3.1.4 • DevTools 2.25.0 macOS 14.0 dart_mappable: ^4.0.1 dart_mappable_builder: ^4.0.1