Git Product home page Git Product logo

Comments (12)

viktordineout avatar viktordineout commented on June 22, 2024 1

None of the above worked for me. This fixed it:

A note which I found in the Freezed readme:

Note:
Freezed will only generate a fromJson if the factory is using =>.

My fromJson function had a body which was defaulting values with putIfAbsent. When replacing the body with the fat arrow, I needed another place to default a value, which I did like so: @Default([]) List<String> staffLogs, in the constructor.

Hope this helps anyone.

from freezed.

rrousselGit avatar rrousselGit commented on June 22, 2024

Without having some code to reproduce the error I cannot help you

A quick check though:
Freezed doesn't generate .g.dart but .freezed.dart.
Did you use the right part?

from freezed.

jhionan avatar jhionan commented on June 22, 2024

from freezed.

rrousselGit avatar rrousselGit commented on June 22, 2024

It may have something to do with the package versions.

build_runner didn't support having a generator outputting dart code for another generator until last week.

from freezed.

jhionan avatar jhionan commented on June 22, 2024

tried to force a version on build_runner, is not that. build_runner dont send any error feedback when generating stuffs.

dev_dependencies: flutter_test: sdk: flutter json_annotation: ^3.0.1 build_runner: ^1.7.4 mockito: 4.1.1 mobx_codegen: ^1.0.1 json_serializable: ^3.2.5 freezed: ^0.2.4

I just used your example:
`import 'package:flutter/foundation.dart';
import 'package:json_annotation/json_annotation.dart';

part 'aaa.freezed.dart';
part 'aaa.g.dart';

@immutable
abstract class Model with _$Model {
factory Model.first(String a) = First;
factory Model.second(int b, bool c) = Second;

factory Model.fromJson(Map<String, dynamic> json) => _$ModelFromJson(json);
}`

and still not generating .g.dart.

from freezed.

rrousselGit avatar rrousselGit commented on June 22, 2024

I see that you're using mobx_codegen. What happens if you remove it?

from freezed.

rrousselGit avatar rrousselGit commented on June 22, 2024

Also, could you try adding the following file at the root of your project?

# build.yaml
targets:
  $default:
    builders:
      freezed|freezed:
        enabled: false


builders:
  freezed:
    import: "package:freezed/builder.dart"
    builder_factories: ["freezed"]
    build_extensions: { ".dart": [".freezed.dart"] }
    auto_apply: dependents
    build_to: source
    runs_before:
      - json_serializable|json_serializable
      - source_gen|combining_builder

from freezed.

jhionan avatar jhionan commented on June 22, 2024

after this build yaml .freezed.dart stopped get generated too. but this can be a clue because I have a build.yaml for json_serializable.
I `ll try a consistent way to reproduce.

from freezed.

nonoyona avatar nonoyona commented on June 22, 2024

On my production project freezed is not generating g.dart file, the problem is that I could not reproduce this bug on a test project.

Creating a test project everything works fine, copying the working fine class of test to production and the .g.dart is not generated.

I tried do add all pubspec dependencies of production project at test project, and test still working.
json_serializable classes are working well when not generated by freezed.

I don't know what to do to find this bug, any idea?

I am having the same issue

Edit: never mind, I just ran pub upgrade and it worked

from freezed.

jhionan avatar jhionan commented on June 22, 2024

Already tried to comment all dependences that could generate stuffs..

So far no good =/

Next test: comment ALL dependences of project and see if it will generate.

from freezed.

rrousselGit avatar rrousselGit commented on June 22, 2024

Sadly I can't do much to help here.

Consider uploading your pubspec.lock and potentially use dependency_overrides to ensure that the version of build_runner+co is the right one

from freezed.

jhionan avatar jhionan commented on June 22, 2024

Sadly I can't do much to help here.

Consider uploading your pubspec.lock and potentially use dependency_overrides to ensure that the version of build_runner+co is the right one

It worked!!!

Just deleted pubspec.lock, I guess build_runner was with an old version, even forcing it on pubspec.

Tks so much!

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.