简体   繁体   English

Flutter Firestore 中的商店列表

[英]Flutter store list in Firestore

I want to store my uploaded images urls to Firestore as list.我想将我上传的图片 url 作为列表存储到 Firestore。

Also I'm trying store multiple images for profile.此外,我正在尝试为个人资料存储多张图片。 This is how I am storing images.这就是我存储图像的方式。 If there is any better way to do that please let me know.如果有更好的方法,请告诉我。

await _firebaseFirestore.collection("noktalar").doc().set({

      'aciklama': aciklama,
      'lat': 123,
      'long': 123,
      'mailAdresi': mailAdresi,
      'noktaAdi': noktaAdi,
      'telefon': tel,
      'webAdresi': webAdresi,
      'yetkiliAdiSoyadi': yetkili,
      'resimler': FieldValue.arrayUnion(resimler)
    });

and I tried this also我也试过了

     'resimler': imagesUrls.map((value) => value.toJson()).toList(),

You can basically store image URLs as a Strings and when you'll get them in code, you can just use split method to make list from String.您基本上可以将图像 URL 存储为字符串,当您在代码中获取它们时,您可以只使用 split 方法从字符串创建列表。 That's pretty easy method to solve this problem这是解决这个问题的非常简单的方法

You can follow the below steps:您可以按照以下步骤操作:

  1. First upload your image to Firebase Storage and get the download URL.首先将您的图片上传到 Firebase 存储并获取下载 URL。
  2. Now you have the download URL and you can Upload your Enter object to Cloud FireStore with the url.现在您已经下载了 URL,您可以使用 url 将您的输入 object 上传到 Cloud FireStore。

You can use the below function to get the download url of uploaded image and then store them in a location in Firestore.您可以使用下面的 function 获取上传图像的下载 url,然后将它们存储在 Firestore 中的某个位置。

Future<String> uploadImage(var imageFile ) async { 
    StorageReference ref = storage.ref().child("/photo.jpg");
    StorageUploadTask uploadTask = ref.putFile(imageFile); 
    var dowurl = await (await uploadTask.onComplete).ref.getDownloadURL();
    url = dowurl.toString(); 
    return url;
 }

You may also refer to the blog .您也可以参考博客

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM