在 style.xml中添加style
dart
<!-- 解决图片裁剪顶状态栏核心主题 -->
<style name="UCropTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#FFE50F</item>
<item name="android:windowLightStatusBar">true</item>
</style>
清单文件中配置
xml
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"
android:theme="@style/UCropTheme"
tools:replace="android:theme"
android:exported="false"/>
代码配置
dart
/*
* 调起裁剪图片
* */
Future<String> cropImage(String imagePath) async {
Completer<String> completer = Completer<String>();
if (imagePath.isNotEmpty) {
final croppedImage = await ImageCropper().cropImage(
sourcePath: imagePath,
aspectRatio: CropAspectRatio(ratioX: 1, ratioY: 1), // 设置特定比率
compressQuality: 100, // 图像质量
maxWidth: 800, // 最大宽度
maxHeight: 800, // 最大高度
uiSettings: [
AndroidUiSettings(
toolbarTitle: '裁剪',
toolbarColor: Colors.white,//标题背景色
// statusBarLight: false,
toolbarWidgetColor: Colors.black,//按钮、标题颜色
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false,
aspectRatioPresets: [
CropAspectRatioPreset.original,
CropAspectRatioPreset.square,
CropAspectRatioPresetCustom(),
],
),
IOSUiSettings(
title: '裁剪'
)
],
);
if (croppedImage != null) {
print('剪切后的图片路径:${croppedImage.path}');
completer.complete(croppedImage.path);
}else{
completer.complete('');
}
}
return completer.future;
}