![](/img/trans.png)
[英]java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity in Flutter App
[英]Flutter image_cropper plugin error: "You need to use a Theme.AppCompat > theme (or descendant) with this activity"
我正在使用 Flutter 的image_cropper 插件,它抛出了关于 AppCompat 的错误:
java.lang.RuntimeException:无法启动活动 ComponentInfo{uk.co.pottertour.meloan/com.yalantis.ucrop.UCropActivity}:java.lang.IllegalStateException:您需要使用 Theme.AppCompat 主题(或后代)与此活动。
发生的情况是:我从我的个人资料编辑屏幕启动相机,在用户拍照后,它应该启动裁剪活动,但它会抛出该错误并使我的整个应用程序崩溃。
最新的 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);
});
}
}
我将裁剪器代码调整为插件自述文件中建议的修订格式,但无济于事。 我想知道在相机完成后屏幕是否需要重建,但是因为相机和 _cropImage 方法是异步的,所以它不及时,所以 Flutter 没有从 main.dart 的根小部件继承main.dart
。
要使用该插件,请将其添加到 AndroidManifest.xml。 特别注意最后一行。
<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.