handleMediaSelection method

Future handleMediaSelection(
  1. PlatformPermisson source
)

Handles media selection based on the requested source

Implementation

Future handleMediaSelection(PlatformPermisson source) async {
  if (source == PlatformPermisson.gallery) {
    // Pick image from gallery
    XFile? xFile = await ImagePicker().pickImage(source: ImageSource.gallery);
    return toFile(xFile);
  } else if (source == PlatformPermisson.camera) {
    // Pick image from camera
    XFile? xFile = await ImagePicker().pickImage(source: ImageSource.camera);
    return toFile(xFile);
  } else if (source == PlatformPermisson.contact) {
    // Pick contact
    dynamic contact = await FlutterContacts.openExternalPick();
    if (contact is Contact) {
      if (contact.phones.length > 1) {
        return contact.phones;
      } else if (contact.phones.length == 1) {
        return contact.phones.first.number;
      }
    }
  } else if (source == PlatformPermisson.storage) {
    return PermissionStatus.granted;
  }
  return null;
}