【问题标题】:Flutter Image_Picker crash iOS app when open Camera打开相机时 Flutter Image_Picker 崩溃 iOS 应用
【发布时间】:2021-11-19 22:39:57
【问题描述】:

当我打开图库或相机时,在 Android 中一切正常,但是当我在 iOS(模拟器和真实设备)上尝试时,图库运行完美,但只要我按下相机选项,应用程序崩溃而没有控制台仅记录“丢失连接到设备”

 // get image File camera
 _getFromCamera(BuildContext context) async {
   XFile? pickedFile = await ImagePicker().pickImage(
     source: ImageSource.camera,
     maxWidth: 1800,
     maxHeight: 1800,
   );
   File rotatedImage =
       await FlutterExifRotation.rotateAndSaveImage(path: pickedFile!.path);
   if (pickedFile != null) {
     image = rotatedImage;
     //File(pickedFile.path);
     final userId = widget.id;
     widget.bloc.uploadProfilePicture(image, userId);
   }
 }

Then I called the function in a Icon button

TextButton.icon(
                     icon: Icon(
                       Icons.photo_camera,
                       color: Theme.of(context).primaryColor,
                     ),
                     label: Text(
                       AppLocalization.of(context)!
                           .getTranslatedValues("cameraLbl")!,
                       style: TextStyle(
                           color: Theme.of(context).colorScheme.secondary,
                           fontWeight: FontWeight.bold),
                     ),
                     onPressed: () {
                       _getFromCamera(context);
                       Navigator.of(context).pop();
                     },
                   )

【问题讨论】:

    标签: ios flutter dart


    【解决方案1】:

    您必须在 info.plist 文件中添加额外的权限

    在其中添加这些条目:

    <key>NSPhotoLibraryUsageDescription</key>
    <string>Needs PhotoLib access</string>
    
    <key>NSCameraUsageDescription</key>
    <string>Needs camera access</string>
    
    

    在flutter应用中添加权限,需要在android manifest和info.plist文件中添加权限。

    您还可以在字符串标签中使用任何字符串,该字符串将显示给用户,作为用户需要授予权限的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-02
      • 2021-05-27
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      • 2019-06-28
      • 2020-12-06
      • 2020-02-28
      相关资源
      最近更新 更多