未处理的异常:'package:firebase_storage / src / storage_reference.dart':失败的断言:第62行pos 12:'file.existsSync()':不正确

时间:2020-05-27 14:45:32

标签: firebase flutter firebase-storage

未处理的异常:'package:firebase_storage / src / storage_reference.dart':断言失败:第62行pos 12:'file.existsSync()':不正确。

在导航中,“ package:firebase_storage / src / storage_reference.dart”中的代码为:

  assert(file.existsSync());
  final _StorageFileUploadTask task =
      _StorageFileUploadTask._(file, _firebaseStorage, this, metadata);
  task._start();
  return task;
}

将图像上载到Firebase存储的代码:

void _selectImage(Future<File> pickImage, int imageNumber) async {
    File tempImg = await pickImage;
    switch (imageNumber) {
      case 1:
        setState(() => _image1 = tempImg);
        break;
      case 2:
        setState(() => _image2 = tempImg);
        break;
      case 3:
        setState(() => _image3 = tempImg);
        break;
      case 4:
        setState(() => _image4 = tempImg);
        break;
    }
  }

  Widget _displayChild1() {
    if (_image1 == null) {
      return Padding(
        padding: const EdgeInsets.fromLTRB(14, 70, 14, 70),
        child: new Icon(
          Icons.add,
          color: Colors.grey.withOpacity(1),
        ),
      );
    } else {
      return Image.file(
        _image1,
        fit: BoxFit.fill,
        width: double.infinity,
      );
    }
  }
 String imageUrl1;
        String imageUrl2;
        String imageUrl3;
        String imageUrl4;
        //  String imageUrl3;
        final FirebaseStorage storage = FirebaseStorage.instance;
        final String picture1 = "1${DateTime.now().millisecondsSinceEpoch.toString()}.jpg";
        StorageUploadTask task1 = storage.ref().child(picture1).putFile(_image1);
        final String picture2 = "2${DateTime.now().millisecondsSinceEpoch.toString()}.jpg";
        StorageUploadTask task2 = storage.ref().child(picture2).putFile(_image2);
        final String picture3 = "3${DateTime.now().millisecondsSinceEpoch.toString()}.jpg";
        StorageUploadTask task3 = storage.ref().child(picture3).putFile(_image3);
        final String picture4 = "4${DateTime.now().millisecondsSinceEpoch.toString()}.jpg";
        StorageUploadTask task4 = storage.ref().child(picture4).putFile(_image4);


        StorageTaskSnapshot snapshot1 =
        await task1.onComplete.then((sanapshot) => sanapshot);
        StorageTaskSnapshot snapshot2 =
        await task2.onComplete.then((sanapshot) => sanapshot);
        StorageTaskSnapshot snapshot3 =
        await task3.onComplete.then((sanapshot) => sanapshot);


        task4.onComplete.then((snapshot4) async {
          imageUrl1 = await snapshot1.ref.getDownloadURL();
          imageUrl2 = await snapshot2.ref.getDownloadURL();
          imageUrl3 = await snapshot3.ref.getDownloadURL();
          imageUrl4 = await snapshot4.ref.getDownloadURL();

          uploadProduct(
            images: imageUrl1,
            images2: imageUrl2,
            images3: imageUrl3,
            images4: imageUrl4,
          );


将图像上传到Firebase存储之前发生错误。 有什么办法吗?

价格货币:2美元(PayPal)

1 个答案:

答案 0 :(得分:0)

这可能是抖动清除的问题,或者我只是删除了应用程序,然后再次重新安装它:) 希望对您有所帮助。