flutterdata / flutter_data

Seamlessly manage persistent data in your Flutter apps
MIT License
410 stars 31 forks source link

Problem with complex class using HasMany #237

Closed Velliane closed 1 year ago

Velliane commented 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

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

frank06 commented 1 year ago

I can't spot issues with that code, is this working now?