Unhandled Exception: Converting object to an encodable object failed: Photography

1,911 views
Skip to first unread message

Bhanuka Isuru

unread,
Jun 26, 2019, 10:49:31 PM6/26/19
to Flutter Development (flutter-dev)
my cloud_firestore looks like this:

all_images:{imageUrl:[]}, couplePhoto:String, female:String, image_url:String, info:String, male:String

my model class: 

 
  import 'package:json_annotation/json_annotation.dart';
    part
'Model.g.dart';
   
   
@JsonSerializable()
   
class Photography {
     
final List<AllImages> all_images;
     
final String couplePhoto;
     
final String female;
     
final String image_url;
     
final String info;
     
final String male;
   
     
Photography(this.all_images, this.couplePhoto, this.female, this.image_url,
         
this.info, this.male);
   
      factory
Photography.fromJson(Map<String, dynamic> json) =>
          _$PhotographyFromJson
(json);
   
     
Map<String, dynamic> toJson() => _$PhotographyToJson(this);
   
}
   
   
@JsonSerializable()
   
class AllImages {
     
final List<String> imageUrl;
   
     
AllImages(this.imageUrl);
   
      factory
AllImages.fromJson(Map<String, dynamic> json) =>
          _$AllImagesFromJson
(json);
   
     
Map<String, dynamic> toJson() => _$AllImagesToJson(this);
   
}


Currently, I haven't adminPanel to data insert. so, now I need to read data.
When running this database, the error is coming in here.

   
     Future<Photography> postsMap = Firestore.instance
           
.collection('photography')
           
.document("0yUc5QBGHNNq6WK9CyyF")
           
.setData(jsonDecode(jsonEncode(Photography)));

Reply all
Reply to author
Forward
0 new messages