Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.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
Android Flatter Image_picker在usb连接但不是应用商店上运行时工作_Android_Flutter - Fatal编程技术网

Android Flatter Image_picker在usb连接但不是应用商店上运行时工作

Android Flatter Image_picker在usb连接但不是应用商店上运行时工作,android,flutter,Android,Flutter,我正在使用一个简单的图像选择器实现。当通过VisualStudio代码在usb连接设备上运行时,这种方法可以很好地工作,但是当我使用“颤振构建appbundle”并将其上传到google play store进行内部测试时,相机功能似乎根本不起作用 我可以完成拍摄照片/视频、预览和选择“确定”,但在这之后,其余功能将失败 _imgFromCamera() async { final String rand = '${new Random().nextInt(10000)}';

我正在使用一个简单的图像选择器实现。当通过VisualStudio代码在usb连接设备上运行时,这种方法可以很好地工作,但是当我使用“颤振构建appbundle”并将其上传到google play store进行内部测试时,相机功能似乎根本不起作用

我可以完成拍摄照片/视频、预览和选择“确定”,但在这之后,其余功能将失败

  _imgFromCamera() async {
    final String rand = '${new Random().nextInt(10000)}';
    final videoName = 'video$rand';
    final image = await picker.getVideo(
      source: ImageSource.camera,
      maxDuration: const Duration(seconds: 10),
    );

    setState(() {
      _image = File(image.path);
    });

    try {
      await _storage
          .ref()
          .child('video/' + videoName)
          .putFile(_image)
          .onComplete;
    } catch (e) {
      print(e.toString());
    }
  }
Pubspec

  image_picker: ^0.6.7+14

  firebase_storage: ^3.0.0
  firebase_core: ^0.4.4
  cloud_firestore: ^0.13.1
firebase正在用于存储照片。

这对我来说很有用:

为视频文件创建支架:

File _video; // Only allow one video
点击按钮,从用户的摄像头获取视频:

Future getvideo() async {
ImagePicker picker = ImagePicker();
PickedFile pickedFile;

// Let user take video with camera
pickedFile = await picker.getVideo(
  source: ImageSource.camera,
  maxDuration: const Duration(seconds: 10),
);

setState(() {
  if (pickedFile != null) {
   _video = File(pickedFile.path);
  } else {
    print('No video selected.');
  }
 });
}
使用另一个按钮提交文件:

// Upload video
if(_video != null) {
  await saveVideoFromFile(_video);
}
saveVideoFromFile函数如下所示:

Future<void> saveVideoFromFile(File _video) async {
  String videoURL = await uploadVideo(_video);
  print(videoURL);
}
Future saveVideoFromFile(File\u video)异步{
字符串videoURL=等待上传视频(_视频);
打印(视频URL);
}
上传视频功能:

Future<String> uploadVideo(File _video) async {
    StorageReference storageReference = FirebaseStorage.instance
        .ref()
        .child('videos/${Path.basename(_video.path)}');
    try {
      StorageUploadTask uploadTask = storageReference.putFile(_video);
      await uploadTask.onComplete;
      print('File Uploaded');
      String returnURL;
      await storageReference.getDownloadURL().then((fileURL) {
        returnURL = fileURL;
      });
      return returnURL;
    } catch (e) {
      print(e);
      return "Error";
    }
  }
未来上传视频(文件\u视频)异步{
StorageReference StorageReference=FirebaseStorage.instance
.ref()
.child('videos/${Path.basename(_video.Path)}');
试一试{
StorageUploadTask uploadTask=storageReference.putFile(_video);
等待上载Task.onComplete;
打印(“文件上传”);
字符串返回URL;
等待storageReference.getDownloadURL()。然后((文件URL){
returnURL=fileURL;
});
返回URL;
}捕获(e){
印刷品(e);
返回“错误”;
}
}

我想知道是不是因为您正在抓取图像并用相同的功能将其保存到云存储而导致崩溃。

您是否收到特定的错误消息?连接时是否将视频保存到Firebase存储?您需要从image_picker软件包执行Android设置吗?