Comments (12)
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.
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.
from freezed.
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.
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.
I see that you're using mobx_codegen. What happens if you remove it?
from freezed.
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.
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.
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.
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.
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.
Sadly I can't do much to help here.
Consider uploading your
pubspec.lock
and potentially usedependency_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)
- 2.4.8 release introduced a new bug: LateInitializationError: Local 'unit' has not been initialized. HOT 3
- Bloc with freezed not working. HOT 23
- Documenting the generated methods copyWith and toJson HOT 2
- 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 1
- 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
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.