【发布时间】: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();
},
)
【问题讨论】: