Home > Software design >  Could not generate `fromJson` code for `images` because of type `Asset`
Could not generate `fromJson` code for `images` because of type `Asset`

Time:01-26

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);
}

CodePudding user response:

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

  •  Tags:  
  • Related