我想在提交提要时在 Firestore 中创建一个空数组。但是该数组在 Firestore 中显示为空。这是我的代码。请帮忙。
class FeedModel {
final String imgUrl;
final String desc;
final String authorName;
final String profileImg;
final String title;
final int likeCount;
List<String> strArr = []; // this the array i want to create it in firestore
FeedModel({this.imgUrl, this.desc,this.authorName,this.profileImg,this.title,this.likeCount, this.strArr});
Map<String, dynamic> toMap(){
return {
"imgUrl" : this.imgUrl,
"desc" : this.desc,
"authorName" : this.authorName,
"profileImg" : this.profileImg,
"like_count" : this.likeCount,
"liked_user_id" : this.strArr
};
}
}
这是发送数据代码:
Future<void> _sendData() async {
try {
final StorageReference firebaseStorageRef = FirebaseStorage.instance.ref().child('myimage.jpg');
final StorageUploadTask task = firebaseStorageRef.putFile(_image);
StorageTaskSnapshot taskSnapshot = await task.onComplete;
String downloadUrl = await taskSnapshot.ref.getDownloadURL();
final String pname = myController.text;
final String pimgurl = downloadUrl;
final String pauthorName = "Sachin Tendulkar";
final String pprofileImg = "https://i.picsum.photos/id/564/200/200.jpg?hmac=uExb18W9rplmCwAJ9SS5NVsLaurpaCTCBuHZdhsW25I";
final String ptitle = "Demo Data";
final int plikeCount= 0;
List<String> pLikeduserId; // This line returning null as show in image
print(pimgurl);
final FeedModel feeds = FeedModel(imgUrl: pimgurl ,desc: pname,authorName: pauthorName ,profileImg: pprofileImg,title: ptitle,likeCount: plikeCount, strArr : pLikeduserId );
insertData(feeds.toMap());
} catch (e) {
print(e);
}
}
创建提要时如何发送像最后一张图片一样的数组?