-
-
Notifications
You must be signed in to change notification settings - Fork 301
Description
Description
I am experiencing a persistent stale default value issue with @Default in freezed.
I created a field as: '@default(1200) int myVal'. Later, I changed this val (like 9000) always resolves to 1200 at runtime, even though: the generated *.freezed.dart file clearly shows = 9000 (The issue only affects this specific field name.)
flutter clean and build_runner build --delete-conflicting-outputs are run
If I rename the field from 'myVal' to 'myVal_' everywhere in the project, the default works correctly (9000) and it changes when I change default value.
If I rename it back from 'myVal_' to 'myVal', the stale value (1200) returns.
This strongly suggests a stale analyzer / build artifact tied to the field name.
flutter clean + build_runner build should fully invalidate previous defaults
I'm not sure how you can create the same issue in your own Flutter project because I don't understand why it's so allergic to the myVal variable. When I try to change the type of this variable from int to String and save it as "9000", freezed completely malfunctions. The following line regarding other variables I saved:
final layoutMode = ref.watch(mySettingsProvider).layoutMode;
causing this issue:
A provider threw the following exception: type 'int' is not a subtype of type 'String?' in type cast
However, the layoutMode variable is of type enum.
(If I name it 'myVal_' and set it to "9000" String, the program works without any problems. There is no another variable as 'myVal' in whole program.)
Environment:
Flutter: 3.38.5
Dart: 3.10.4
freezed: 3.2.3
build_runner: 2.10.4
IDE: VS Code
Additional notes: Manually deleting .dart_tool/ and build folder, and reloading the IDE analyzer don't resolves the issue.