Unhandled Exception: 'package:firebase_storage/src/storage_reference.dart': Failed assertion: line 62 pos 12: 'file.existsSync()': is not true

那年仲夏 提交于 2020-06-01 05:07:37

问题


Unhandled Exception: 'package:firebase_storage/src/storage_reference.dart': Failed assertion: line 62 pos 12: 'file.existsSync()': is not true.

On naviagtion, code in 'package:firebase_storage/src/storage_reference.dart' is :

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

Code of uplading image to firebase storage:

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,
          );


An error occurs before uploading images to firebase storage. Any solutions?

Price money: $2 (PayPal)


回答1:


This may be a problem of flutter clean or i just did delete app and re-install it again :) Hope it help.



来源:https://stackoverflow.com/questions/62045943/unhandled-exception-packagefirebase-storage-src-storage-reference-dart-fail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!