【问题标题】:Save Image Url in Cloud FireStore在 Cloud FireStore 中保存图像 URL
【发布时间】:2020-03-05 10:36:24
【问题描述】:

我尝试在 Cloud FireStore 中创建产品的详细信息。创建文档并将图像保存在存储中是所有工作。 Mu 问题是图像 url 未保存在文档中。

飞镖文件

  class ProductService {
  Firestore _firestore = Firestore.instance;

  void createProduct(_nameproductController, _priceproductController,
      _currentCategory, url) async {

    _firestore.collection("products").document().setData({
      'name': _nameproductController,
      'price': _priceproductController,
      'category': _currentCategory,
      'image': url,
    });
  }
}

上传图片

void uploadImg() async {
var timekey = DateTime.now();
fb.StorageReference storageReference =
    fb.storage().ref('imgProduct/${timekey.toString()}.jpg');
fb.UploadTaskSnapshot uploadTask = await storageReference
    .put(_image1, fb.UploadMetadata(contentType: 'image/jpg'))
    .future;

var imageUrl = await uploadTask.ref.getDownloadURL();

url = imageUrl.toString();
print('Image Url' + url);}

提交按钮

RaisedButton(
   onPressed: () async {
     if (_formKeyProduct.currentState.validate()) {
        uploadImg();
        ProductService().addProduct(
         _nameproductController.text,
         _priceproductController.text,
         _currentCategory.categoryname.toString(),
         url,
        );

        _formKeyProduct.currentState.reset();
        _nameproductController.clear();
        _priceproductController.clear();
     }

     setState(() {
        _currentCategory = null;
     });
  },

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    你需要等待 uploadImg();

    【讨论】:

      猜你喜欢
      • 2019-09-21
      • 1970-01-01
      • 1970-01-01
      • 2011-11-04
      • 2021-03-14
      • 2018-04-13
      • 2020-08-09
      • 2012-03-30
      • 1970-01-01
      相关资源
      最近更新 更多