checkStoragePermission method

Future<bool> checkStoragePermission(
  1. BuildContext context
)

Implementation

Future<bool> checkStoragePermission(BuildContext context) async {
  if (!Platform.isAndroid) return true; // iOS doesn’t need it

  // ✅ If app already has full access
  if (await Permission.manageExternalStorage.isGranted) return true;

  // ✅ Android 13+ scoped video permission
  if (await Permission.videos.isGranted) return true;

  // 🔹 Request permissions in proper order
  if (await Permission.manageExternalStorage.request().isGranted) {
    return true;
  }

  if (await Permission.videos.request().isGranted) {
    return true;
  }

  await showDialog(
    context: context,
    builder: (context) => AlertDialog(
      title: const Text("Permission Required"),
      content: const Text(
          "Please enable storage permission from app settings to download videos."),
      actions: [
        TextButton(
          onPressed: () {
            openAppSettings();
            Navigator.of(context).pop();
          },
          child: const Text("Open Settings"),
        ),
      ],
    ),
  );

  return false;
}