简体   繁体   English

Flutter image_cropper 插件错误:“您需要在此活动中使用 Theme.AppCompat > 主题(或后代)”

[英]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.

相关问题 java.lang.IllegalStateException:您需要在 Flutter App 中使用 Theme.AppCompat 主题(或后代)与此活动 - java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity in Flutter App Flutter : local_auth: ^0.6.1 : PlatformException(error, You need to use a Theme.AppCompat theme (or后代) with this Activity., null) - Flutter : local_auth: ^0.6.1 : PlatformException(error, You need to use a Theme.AppCompat theme (or descendant) with this activity., null) 如何在 flutter web 中使用 image_cropper? - How to use image_cropper in flutter web? 抖动 image_cropper 崩溃 - flutter image_cropper crash 如何通过设置 theme.appcompat 解决 flutter 支付问题? - How to resolve flutter payment issue with setting theme.appcompat? image_cropper 在 flutter 中使应用程序崩溃 - image_cropper crashing the app in flutter Flutter - 如何更改 image_cropper 组件中的语言? - Flutter - how change language in image_cropper component? 如何从 flutter 中的 image_cropper 获取路径? - how to get the path from image_cropper in flutter? 颤动:添加“image_cropper”和“contacts_service”包时构建错误 - Flutter: build error when adding “image_cropper” and “contacts_service” packages 如何使用 image_cropper 包裁剪图像? - how to crop image in flutter using image_cropper package?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM