3

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);
}
  • if what you want is to load a list of images from the assets you can name the images with numbers ordered in such a way that when you want to have the list you can say i.jpg – Elvis Salabarria Aquino Jan 25 '22 at 19:42

1 Answers1

3

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

Craig Labenz
  • 2,489
  • 3
  • 22
  • 17
  • 1
    When since they need a custom? cause before i update the libraries i was not getting that problem, and today, i got i! – SalahAdDin Apr 20 '22 at 18:30