confirmAndUploadNewImage function

Future<CropParameters?> confirmAndUploadNewImage(
  1. BuildContext context, {
  2. required CropHelper cropHelper,
  3. required bool isLoggedInMandatory,
  4. UserPictureSource? forcedSource,
})

Lets the user pick a picture, crop it, and save it.

Implementation

Future<CropParameters?> confirmAndUploadNewImage(
  BuildContext context, {
  required CropHelper cropHelper,
  required bool isLoggedInMandatory,
  UserPictureSource? forcedSource,
}) async {
  final XFile? fullPhoto = await pickImageFile(
    context,
    forcedSource: forcedSource,
  );
  if (fullPhoto == null) {
    return null;
  }
  if (!context.mounted) {
    return null;
  }
  return Navigator.of(context).push<CropParameters>(
    MaterialPageRoute<CropParameters>(
      builder: (BuildContext context) => CropPage(
        inputFile: File(fullPhoto.path),
        initiallyDifferent: true,
        isLoggedInMandatory: isLoggedInMandatory,
        cropHelper: cropHelper,
        onRetakePhoto: () => pickImageFile(
          context,
          forcedSource: forcedSource,
        ).then((XFile? file) => file != null ? File(file.path) : null),
      ),
      fullscreenDialog: true,
    ),
  );
}