picImage function

Future<File?> picImage(
  1. BuildContext context
)

Implementation

Future<File?> picImage(BuildContext context) async {
  ImageSource? source = await showDialog<ImageSource>(
      context: context,
      builder: (BuildContext context) {
        return SimpleDialog(
          title: Text(S.of(context)?.add_photo ?? 'Add photo'),
          children: <Widget>[
            SimpleDialogOption(
              onPressed: () {
                FocusScope.of(context).unfocus();
                Navigator.pop(context, ImageSource.camera);
              },
              child: ListTile(
                leading: const Icon(Icons.camera_alt),
                title: Text(S.of(context)?.camera??'Camera'),
              ),
            ),
            SimpleDialogOption(
              onPressed: () {
                FocusScope.of(context).unfocus();
                Navigator.pop(context, ImageSource.gallery);
              },
              child: ListTile(
                leading: const Icon(Icons.image),
                title: Text(S.of(context)?.gallery??'Gallery'),
              ),
            ),
          ],
        );
      });

  if (source == null) return null;

  final pickedFile = await ImagePicker().pickImage(source: source);
  if (pickedFile == null) return null;

  File image = File((pickedFile).path);
  return fixExifRotation(image);
}