pickImage static method

Future<File?> pickImage(
  1. BuildContext context, {
  2. bool isVideo = false,
})

Show bottom-sheet chooser (camera/gallery). Returns picked File or null.

Implementation

static Future<File?> pickImage(BuildContext context, {bool isVideo = false}) async {
  if (!await requestStoragePermission(context)) return null;
  if (!context.mounted) return null;

  return showModalBottomSheet<File?>(
    context: context,
    builder: (BuildContext sheetContext) {
      return SafeArea(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            ListTile(
              leading: const Icon(Icons.camera_alt),
              title: const Text('Camera', style: TextStyle(fontSize: 14)),
              onTap: () async {
                final f = await pickImageFromCamera(isVideo: isVideo);
                if (sheetContext.mounted) Navigator.pop(sheetContext, f);
              },
            ),
            ListTile(
              leading: const Icon(Icons.photo_library),
              title: const Text('Gallery', style: TextStyle(fontSize: 14)),
              onTap: () async {
                final f = await pickImageFromGallery(isVideo: isVideo);
                if (sheetContext.mounted) Navigator.pop(sheetContext, f);
              },
            ),
          ],
        ),
      );
    },
  );
}