Questions tagged [flutter-freezed]
95 questions
9
votes
3 answers
Type 'Null' is not a subtype of type 'Map' in type cast error
In my sample project I implemented project with riverpod package and freezed. In the code below, I can get data from the server successfully, but when I try to use model.fromJson I get this error:
getting type 'Null' is not a subtype of type…

DolDurma
- 15,753
- 51
- 198
- 377
6
votes
2 answers
Freezed class with enum property throws error upon trying to serialize
I have a freezed class that takes an enum in its constructor, but when trying to perform the jsonEncode method on this class, it fails with the following error:
The following JsonUnsupportedObjectError was thrown while handling a gesture:
Converting…

Luca Cras
- 61
- 1
- 3
5
votes
0 answers
flutter: Can't modify list because of Unsupported operation: Cannot modify an unmodifiable list
I'm trying to modify item value in list, which always results Can't modify list because of Unsupported operation: Cannot modify an unmodifiable list
I'm using bloc state-management and freezes as code generator.
Here is my code:
Get roles from…

veesilenavi
- 51
- 1
- 2
5
votes
1 answer
Flutter Firebase How to convert DocumentSnapshot to Model Json inside a model class
I have this Firebase Document that I want to convert to a JSON and add Id to it when using it within the app.
factory Recipe.fromDocument(DocumentSnapshot doc) {
final data = doc.data()!;
return Recipe.fromJson(data).copyWith(id: doc.id);
…

Millenial2020
- 2,465
- 9
- 38
- 83
5
votes
2 answers
json_serializable - Add a generic field to a freezed/json_serializable class
How do I make a Freezed object take a generic type? I want to do this:
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:vepo/src/entity_types/option_entity.dart';
part 'vegan_item_tag.freezed.dart';
part…

BeniaminoBaggins
- 11,202
- 41
- 152
- 287
4
votes
2 answers
Riverpod trigger rebuild when update state with freezed copywith even if nothing changed
I thought Riverpod will only trigger rebuild if the state value is different but turn out it rebuild every time when state is set although the value is the same. Is that true?
The case is as below
@Freezed(genericArgumentFactories: true)
class Model…

Anson Wong
- 1,034
- 8
- 10
4
votes
1 answer
In Freezed generated classes, how to check if two objects are the same instance?
I'm using Freezed for dart immutable data modelling. This generator is overwriting == operator and the hasCode, which is fine for 99% of cases.
But I have a special case where comparing a long list take time and the List is managed internally.…

angelcervera
- 3,699
- 1
- 40
- 68
4
votes
1 answer
flutter : freezed required nor marked with @Default
I am trying to use freezed on my application, So I added
environment:
sdk: ">=2.7.0<3.0.0"
freezed: ^0.14.0
freezed_annotation: ^0.14.0
to my dependencies.
dev_dependencies:
freezed_annotation: ^0.12.0
build_runner: ^2.0.1
…

Cyrus the Great
- 5,145
- 5
- 68
- 149
4
votes
0 answers
Implement freezed with Hive and inheritance
I have read the documentation but still not able to understand how it works with polymorphism.
See the example code I wish to achieve:
abstract class BaseUser extends HiveObject {
@HiveField(1)
final String name;
BaseUser({required…

Hashir Shoaib
- 41
- 2
3
votes
1 answer
Best way to have a const factory for empty instance in Flutter's freezed
I am trying to figure out the best way to implement a constant factory for "empty" instance of the defined model while keeping its original constructor strict (require all arguments without defaults).
The closest solution I could get is using Union…

Roman Shirokov
- 329
- 4
- 12
3
votes
1 answer
How to ignore null value toJson using freezed?
I've tried to create a profile model like this; fromJson looks good, but I have a problem with toJson:
@Freezed(
fromJson: true,
toJson: true,
map: FreezedMapOptions.none,
when: FreezedWhenOptions.none,
)
class ProfileAttribute with…

Afdal
- 501
- 9
- 19
3
votes
1 answer
Could not generate `fromJson` code for `images` because of type `Asset`
I am using freezed with json generator. i am facing this error on generating the code.
Could not generate fromJson code for images because of type
Asset.
The Code Is:
abstract class ProductDTO with _$ProductDTO {
factory ProductDTO({
…
user16906111
3
votes
0 answers
Failed to build build_runner:build_runner:
I'm trying to run flutter packages pub run build_runner build --delete-conflicting-outputs to generate freezed files but I'm getting this error.
Failed to build…

Bhawna Saroha
- 603
- 1
- 11
- 28
2
votes
1 answer
How to dynamically pass the T.fromJson() to Flutter class with List of ?
I'm working on the ApiResponse class of my Flutter project and this class needs a T data attribut.
I want to use JsonSerializable to generate the fromJson() method but this error appears when I tried to :
ListResponse _$ListResponseFromJson

YannMLD
- 21
- 2
2
votes
1 answer
Passing in ID for a firestore document converting to a freezed data class (fromJson)
What is the best way to return a document from firebase when the id is not coming from the json firestore returns, using a freezed data class with fromJson/toJson?
I want the id to be required (to make sure I always have one - and plan to use an…

Charlie Page
- 541
- 2
- 17