Closed Velliane closed 1 year ago
Hi,
I'm using freezed with flutter_data, but I have a problem with complex class.
@freezed @DataRepository([]) class Result extends DataModel<Result> with _$Result { Result._(); factory Result({ int? id, required HasMany<Details> results, }) = _Result; factory Result.fromJson(Map<String, Object?> json) => _$ResultFromJson(json); } @freezed @DataRepository([]) class Details extends DataModel<Details> with _$Details { Details._(); factory Details({ required String id, required String name, }) = _Details; factory Details.fromJson(Map<String, Object?> json) => _$DetailsFromJson(json); }
I use HasMany for list of Details, but I have this error type 'List<dynamic>' is not a subtype of type 'Map<String, dynamic>' in type cast
type 'List<dynamic>' is not a subtype of type 'Map<String, dynamic>' in type cast
Here the generated function in the g.dart file:
_$_Result _$$_ResultFromJson(Map<String, dynamic> json) => _$_Result( id: json['id'] as int?, results: HasMany<Details>.fromJson( json['results'] as Map<String, dynamic>), );
Did i miss something ? Thanks for your help
I can't spot issues with that code, is this working now?
Hi,
I'm using freezed with flutter_data, but I have a problem with complex class.
I use HasMany for list of Details, but I have this error
type 'List<dynamic>' is not a subtype of type 'Map<String, dynamic>' in type cast
Here the generated function in the g.dart file:
Did i miss something ? Thanks for your help