Search code examples
jsonflutterjsonserializerfreezedflutter-freezed

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({
    required String description,
    required List<Asset> images, // error
  }) = _ProductDTO;

  // from Json
  factory ProductDTO.fromJson(Map<String, dynamic> json) =>
      _$ProductDTOFromJson(json);
}

Solution

  • Custom data types require specific converters to handle their toJson and fromJson implementations. This question and its answers provide some nice examples.