Code Monkey home page Code Monkey logo

Comments (12)

rrousselGit avatar rrousselGit commented on July 23, 2024 3

Done 👌

from freezed.

rrousselGit avatar rrousselGit commented on July 23, 2024 1

I'll take a look, thanks

from freezed.

rrousselGit avatar rrousselGit commented on July 23, 2024 1

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.

rrousselGit avatar rrousselGit commented on July 23, 2024

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.

ResoDev avatar ResoDev commented on July 23, 2024

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.

rrousselGit avatar rrousselGit commented on July 23, 2024

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.

ResoDev avatar ResoDev commented on July 23, 2024

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.

ResoDev avatar ResoDev commented on July 23, 2024

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.

rrousselGit avatar rrousselGit commented on July 23, 2024

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.

ResoDev avatar ResoDev commented on July 23, 2024

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.

rrousselGit avatar rrousselGit commented on July 23, 2024

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.

ResoDev avatar ResoDev commented on July 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.