Future<File?>
startImageCropping(- dynamic context
)
Implementation
Future<File?> startImageCropping(BuildContext context) async {
final bool isDarktheme =
Provider.of<ThemeProvider>(context, listen: false).isDarkMode(context);
final Color? themeColor = isDarktheme
? Colors.black
: Theme.of(context).appBarTheme.backgroundColor;
final Color widgetColor = isDarktheme ? Colors.white : Colors.black;
final ImagePicker picker = ImagePicker();
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final XFile? pickedXFile = await picker.pickImage(
source: ImageSource.camera,
);
if (pickedXFile == null) {
return null;
}
final CroppedFile? croppedFile = await ImageCropper().cropImage(
sourcePath: pickedXFile.path,
aspectRatioPresets: <CropAspectRatioPreset>[
CropAspectRatioPreset.square,
CropAspectRatioPreset.ratio3x2,
CropAspectRatioPreset.original,
CropAspectRatioPreset.ratio4x3,
CropAspectRatioPreset.ratio16x9
],
uiSettings: <PlatformUiSettings>[
AndroidUiSettings(
toolbarTitle: appLocalizations.product_edit_photo_title,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false,
statusBarColor: themeColor,
toolbarColor: themeColor,
toolbarWidgetColor: widgetColor,
//ignore: use_build_context_synchronously
activeControlsWidgetColor: Theme.of(context).colorScheme.primary,
backgroundColor: themeColor,
),
IOSUiSettings(
minimumAspectRatio: 1.0,
),
],
);
return File(croppedFile!.path);
}