[英]Flutter image_cropper plugin error: "You need to use a Theme.AppCompat > theme (or descendant) with this activity"
I'm using Flutter's image_cropper plugin & it's throwing an error about AppCompat:我正在使用 Flutter 的image_cropper 插件,它抛出了关于 AppCompat 的错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{uk.co.pottertour.meloan/com.yalantis.ucrop.UCropActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. java.lang.RuntimeException:无法启动活动 ComponentInfo{uk.co.pottertour.meloan/com.yalantis.ucrop.UCropActivity}:java.lang.IllegalStateException:您需要使用 Theme.AppCompat 主题(或后代)与此活动。
What happens is: I launch the camera from my profile edit screen, after the user takes a photo, it should then launch the crop activity, but it throws that error and crashes my entire app.发生的情况是:我从我的个人资料编辑屏幕启动相机,在用户拍照后,它应该启动裁剪活动,但它会抛出该错误并使我的整个应用程序崩溃。
This has started to happen with the latest image_cropper plugin upgrade, 2.0.3.最新的 image_cropper 插件升级 2.0.3 开始出现这种情况。
Future getImage(ImageSource _imageSource) async {
final pickedFile =
await imagePicker.pickImage(source: _imageSource, imageQuality: 85);
if(pickedFile == null) return;
print(LOG + "getImage file from camera path: ${pickedFile.path}");
_cropImage(pickedFile.path);
setState(() {
_image = File(pickedFile.path);
});
imageChanged = true;
}
Future<Null> _cropImage(String imageFilePath) async {
final croppedFile = await ImageCropper().cropImage(
compressQuality: 80,
sourcePath: imageFilePath,
maxWidth: 428,
maxHeight: 428,
aspectRatioPresets: Platform.isAndroid
? [
CropAspectRatioPreset.square,
]
: [
CropAspectRatioPreset.square,
],
uiSettings: [
AndroidUiSettings(
toolbarTitle: 'Cropper',
toolbarColor: Colors.deepOrange,
toolbarWidgetColor: Colors.white,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: true),
IOSUiSettings(
title: 'Cropper',
)
]);
if (croppedFile != null) {
setState(() {
_image = File(croppedFile.path);
});
}
}
I tweaked the cropper code, to the revised format suggested in the plugin's readme but to no avail.我将裁剪器代码调整为插件自述文件中建议的修订格式,但无济于事。 I wonder if the screen needs to rebuild after the camera completes but because the camera & _cropImage methods are async, it doesn't in time, so Flutter doesn't have appCompat inherited from the root widget from main.dart
.我想知道在相机完成后屏幕是否需要重建,但是因为相机和 _cropImage 方法是异步的,所以它不及时,所以 Flutter 没有从 main.dart 的根小部件继承main.dart
。
To use the plugin add this to AndroidManifest.xml.要使用该插件,请将其添加到 AndroidManifest.xml。 Pay attention especially to the last line.特别注意最后一行。
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.