Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter iOS应用程序在连续两次调用此函数时崩溃(Firebase存储,Flatter)_Flutter_Google Cloud Firestore_Firebase Storage - Fatal编程技术网

Flutter iOS应用程序在连续两次调用此函数时崩溃(Firebase存储,Flatter)

Flutter iOS应用程序在连续两次调用此函数时崩溃(Firebase存储,Flatter),flutter,google-cloud-firestore,firebase-storage,Flutter,Google Cloud Firestore,Firebase Storage,我的应用程序在连续两次调用“_submit”函数时崩溃。 我可以从gallery中选择图片并将其上传到Firebase存储,但如果我再次调用它,整个应用程序将崩溃 从该按钮: floatingActionButton: FloatingActionButton( onPressed: () => _submit(), Submit调用数据库类型的提供程序: Future<void> _submit() async { widget.database

我的应用程序在连续两次调用“_submit”函数时崩溃。 我可以从gallery中选择图片并将其上传到Firebase存储,但如果我再次调用它,整个应用程序将崩溃

从该按钮:

 floatingActionButton: FloatingActionButton(
        onPressed: () => _submit(),
Submit调用数据库类型的提供程序:

Future<void> _submit() async {
    widget.database = Provider.of<Database>(context, listen: false);
    await widget.database
        .setPicture("regione/citta/comune/lavoro/IDArtista/profilo.png");
    return;
  }
Future\u submit()异步{
widget.database=Provider.of(上下文,侦听:false);
等待widget.database
.setPicture(“regione/citta/comune/lavoro/IDArtista/profilo.png”);
返回;
}
调用将从“imgGallery()”拍摄的照片上载到数据库的函数:

Future<void> setPicture(String pathStorage) async {
    try {
      final File file = await imgFromGallery();
      if (file == null) return;
      TaskSnapshot task =
          await FirebaseStorage.instance.ref(pathStorage).putFile(file);
      String image_url = await task.ref.getDownloadURL();
      return;
    } catch (e) {
      print(e);
      return;
    }
  }
Future setPicture(字符串路径存储)异步{
试一试{
最终文件文件=等待imgFromGallery();
if(file==null)返回;
任务快照任务=
等待FirebaseStorage.instance.ref(路径存储).putFile(文件);
字符串image_url=wait task.ref.getDownloadURL();
返回;
}捕获(e){
印刷品(e);
返回;
}
}
imgGallery:

Future<File> imgFromGallery() async {
  try {
    final ImagePicker _picker = ImagePicker();
    final PickedFile imageFile =
        await _picker.getImage(source: ImageSource.gallery, imageQuality: 50);

    //If there is no image selected, return.
    if (imageFile == null) return null;
    //File created.
    File tmpFile = File(imageFile.path);
    //it gives path to a directory - path_provider package.
    final appDir = await getApplicationDocumentsDirectory();
    //filename - returns last part after the separator - path package.
    final fileName = tmpFile.path.split('/').last;
    //copy the file to the specified directory and return File instance.
    return tmpFile = await tmpFile.copy('${appDir.path}/$fileName');
  } catch (e) {
    print(e);
    return null;
  }
}
Future imgFromGallery()异步{
试一试{
最终图像选择器_picker=图像选择器();
最终选取的文件imageFile=
wait_picker.getImage(来源:ImageSource.gallery,imageQuality:50);
//如果没有选择图像,则返回。
if(imageFile==null)返回null;
//文件已创建。
File tmpFile=File(imageFile.path);
//它提供目录路径\提供程序包的路径。
final appDir=等待getApplicationDocumentsDirectory();
//filename-返回separator-path包后面的最后一部分。
最终文件名=tmpFile.path.split(“/”).last;
//将文件复制到指定目录并返回文件实例。
return tmpFile=wait tmpFile.copy('${appDir.path}/$fileName');
}捕获(e){
印刷品(e);
返回null;
}
}

编辑:使用真实设备而不是模拟器来解决此问题。

您在哪个设备中遇到此问题?我也有这个错误,但只有在iOS模拟器上。它与Image_Picker包和FocusNode有关。在github上查看此信息

如果你的应用程序崩溃,请(始终)提供确切的错误消息和崩溃的完整堆栈跟踪。我没有堆栈跟踪,我认为对于“尝试和捕获”,请给我几分钟时间,让我看看当库出现时它崩溃的方式。我在哪里可以看到堆栈跟踪?调试控制台显示“退出”:(iOS模拟器我也是,我会尝试使用真实的手机,因为当gallery出现时它会崩溃!嗨@Federico'Armini,你在物理设备上尝试过吗?如何进行?在真实设备上它工作正常,抱歉,我忘记更新了!