Comments (12)
Done 👌
from freezed.
I'll take a look, thanks
from freezed.
I think that instead of "don't generate if it doesn't mix-in _$MyCLass", I'll go with "don't generate if the class has a property"
from freezed.
Basically it adds a DiagnosticableTreeMixin to the generated file's classes.
That's expected
It sounds more like a problem with parsing the name.
Could you give a minimalist way of reproducing the error?
from freezed.
When creating the demo project, I probably found the root of the issue. Code gen kicks in even for classes which don't extend _$SomeClass
. While this minimal project written as a console app produces errors, they are not the same as in the case which I described with the BLoC.
UPDATE: The repository now also contains a minimal example with BLoC where Event
is freezed and State
is just a regular class marked as @immutable
.
from freezed.
Note that removing the @immutable
on NonFreezedClass
will fix the issue.
I'll think of a proper fix. The main problem is, since the interface is generated, the analyzer doesn't pick it up because it doesn't exist yet
from freezed.
Removing @immutable
works in the example, even with BLoC. For some reason though, this doesn't work on my real code. I can't really share it as there's a lot of specifics going on and it's definitely not a minimal example.
In the meantime, I'll try to migrate the regular class to a freezed data class. That should work 🤞
from freezed.
Sounds reasonable. Anyway, this issue forced me to rethink my legacy approach to pure immutable classes and now I use freezed even for them. Works perfectly, thanks again!
I just have to use static
methods instead of factories to have "predefined state configurations" which is a bit of an antipattern in Dart but I can live with that 😄
from freezed.
I just have to use static methods instead of factories to have "predefined state configurations" which is a bit of an antipattern in Dart but I can live with that 😄
What do you mean?
from freezed.
Well, the static
method is an anti-pattern, isn't it? I even have to ignore lint.
@immutable
abstract class SignInFormState with _$SignInFormState {
const factory SignInFormState({
EmailAddress validatedEmailAddress,
Password validatedPassword,
bool autovalidate,
bool isSubmitting,
Either<AuthFailure, Unit> isSuccess,
}) = _SignInFormState;
// ignore: prefer_constructors_over_static_methods
static SignInFormState initial() {
return SignInFormState(
validatedEmailAddress: EmailAddress(''),
validatedPassword: Password(''),
autovalidate: false,
isSubmitting: false,
isSuccess: null,
);
}
}
from freezed.
Yeah I forgot to test that. I'll fix it.
But to be fair, your example should be a static const
instead of a static function
from freezed.
Kind of, but EmailAddress
cannot be const
anyway as there's some validation going on inside of it. Otherwise, you're correct.
from freezed.
Related Issues (20)
- Setting the flag `@Freezed(toJson: false)` creates an error in the generated freezed files when we define a custom `toJson`.
- Problem with fromJson in web app HOT 1
- Generics complicate self-referential class structure HOT 2
- Add support for required constructor parameters that are ignored by freezes HOT 1
- Why not integrate the FieldRename functionality from JsonSerializable into Freezed? HOT 1
- Why not integrate a annotation to rename JSON fields (like in JsonSerializable)? HOT 3
- Confusing legacy tag for "Union types and Sealed classes" HOT 5
- Switch from a model M1 to a model M2 HOT 1
- Arguments of a constant creation must be constant expressions. When adding custom converter with json_serializable HOT 2
- Add support for default value on copyWith
- Add default value for field on copyWith HOT 3
- LinkedHashMap, HashMap is mutable with @freezed HOT 1
- If the path does not start with the lib folder, is it ignored? HOT 1
- Support both analyzer versions HOT 2
- Using macros insted build_runner HOT 1
- freezed and macros HOT 1
- freezed 2.5.3 analyzer 6.5.0 problem HOT 8
- support makeCollectionsUnmodifiable in build.yaml
- Freezed 2.5.3 doesn't work with latest stable Flutter HOT 3
- Annotation to exclude some arguments for toString
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freezed.