title: Flutter image_picker package returns null when trying to retrieve a video from the gallery
body: <p>I am trying to build an app that lets users select videos and upload them, so for this, I am using the image_picker package. However, I am currently running tests and whenever I try to select a video from the gallery, instead of getting a file back I get null. I don't know if the problem is with how I am using the package or with permissions, although according to the package you don't need permissions for android.</p>
  
  <p>Below the function in my code that is giving me trouble:</p>
  
  <pre><code>handleChooseFromGallery() async {
  Navigator.pop(context);
  File filePicked = await ImagePicker.pickVideo(
    source: ImageSource.gallery,
    maxDuration: Duration(seconds: 90),
  );
  //This line always returns false
  print({'is file not null': filePicked != null});
  setState(() {
    if (filePicked != null) {
      this.files.add(filePicked);
      this.selected = true;
    } else {
      showError();
    }
  });
    }
  </code></pre>
  
  <p>The complete code (minus completely irrelevant things):</p>
  
  <pre><code>import 'dart:io';
  
  import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  import 'package:golfapp/data/course_data.dart';
  import 'package:golfapp/data/user_data.dart';
  import 'package:provider/provider.dart';
  import 'package:image_picker/image_picker.dart';
  import 'package:uuid/uuid.dart';
  import 'package:firebase_storage/firebase_storage.dart';
  import 'package:cloud_firestore/cloud_firestore.dart';
  
  import 'package:golfapp/data/semana_data.dart';
  import 'package:golfapp/widgets/chewie_item.dart';
  
  final StorageReference storageRef = FirebaseStorage.instance.ref();
  final postsRef = Firestore.instance.collection('posts');
  final DateTime timestamp = DateTime.now();
  
  class DetailScreen extends StatefulWidget {
    final int index;
    final String photoUrl;
    final String videoUrl;
  
    DetailScreen({this.index, this.photoUrl, this.videoUrl});
  
    @override
    _DetailScreenState createState() =&gt; _DetailScreenState();
  }
  
  class _DetailScreenState extends State&lt;DetailScreen&gt; {
    bool isUploading = false;
    bool selected = false;
    List&lt;File&gt; files = [];
    String postId = Uuid().v4();
    TextEditingController captionController = TextEditingController();
  
    showError() {
      showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Row(
              children: [
                Padding(
                  padding: EdgeInsets.only(right: 10.0),
                  child: Text('Error'),
                ),
                Icon(Icons.error_outline, size: 60.0),
              ],
            ),
            content: SingleChildScrollView(
              child: ListBody(
                children: [
                  Text(
                    'Hubo un error con el video seleccionado.',
                    style: TextStyle(
                      fontFamily: 'Montserrat',
                      fontWeight: FontWeight.w600,
                      fontSize: 17.0,
                    ),
                  ),
                ],
              ),
            ),
          );
        },
      );
    }
  
    clearImage() {
      setState(() {
        this.selected = false;
      });
    }
  
    handleTakePhoto() async {
      Navigator.pop(context);
      File fileTaken = await ImagePicker.pickVideo(
        source: ImageSource.camera,
        maxDuration: Duration(seconds: 90),
      );
      setState(() {
        if (fileTaken != null) {
          this.files.add(fileTaken);
          this.selected = true;
        } else {
          showError();
        }
      });
    }
  
    handleChooseFromGallery() async {
      Navigator.pop(context);
      File filePicked = await ImagePicker.pickVideo(
        source: ImageSource.gallery,
        maxDuration: Duration(seconds: 90),
      );
      print({'is file not null': filePicked != null});
      setState(() {
        if (filePicked != null) {
          this.files.add(filePicked);
          this.selected = true;
        } else {
          showError();
        }
      });
    }
  
    selectImage(parentContext) {
      return showDialog(
        context: parentContext,
        builder: (context) {
          return SimpleDialog(
            title: Text("Seleccionar video"),
            children: &lt;Widget&gt;[
              SimpleDialogOption(
                child: Text("Tomar video"),
                onPressed: handleTakePhoto,
              ),
              SimpleDialogOption(
                child: Text("Video de la galería"),
                onPressed: handleChooseFromGallery,
              ),
              SimpleDialogOption(
                child: Text("Cancelar"),
                onPressed: () =&gt; Navigator.pop(context),
              )
            ],
          );
        },
      );
    }
  
    Future&lt;String&gt; uploadVideo(imageFile) async {
      StorageUploadTask uploadTask = storageRef
          .child(Provider.of&lt;UserData&gt;(context, listen: false).user.id)
          .child(Provider.of&lt;CourseData&gt;(context, listen: false).course.uid)
          .child(Provider.of&lt;SemanaData&gt;(context, listen: false).semana.uid)
          .putFile(imageFile, StorageMetadata(contentType: 'video/mp4'));
      StorageTaskSnapshot storageSnap = await uploadTask.onComplete;
      String downloadUrl = await storageSnap.ref.getDownloadURL();
      return downloadUrl;
    }
  
    createPostInFirestore({List&lt;String&gt; mediaUrl, String description}) {
      postsRef
          .document(Provider.of&lt;UserData&gt;(context, listen: false).user.id)
          .collection("userPosts")
          .document(Provider.of&lt;CourseData&gt;(context, listen: false).course.uid)
          .setData({
        "semana": Provider.of&lt;SemanaData&gt;(context, listen: false).semana.uid,
        "postId": postId,
        "ownerId": Provider.of&lt;UserData&gt;(context, listen: false).user.id,
        "username": Provider.of&lt;UserData&gt;(context, listen: false).user.username,
        "mediaUrl": mediaUrl,
        "description": description,
        "timestamp": timestamp,
        "likes": {},
      });
    }
  
    handleSubmit() async {
      setState(() {
        isUploading = true;
      });
      List&lt;String&gt; mediaUrlS = [];
      for (File fileLoop in files) {
        String mediaUrl = await uploadVideo(fileLoop);
        mediaUrlS.add(mediaUrl);
      }
      createPostInFirestore(
        mediaUrl: mediaUrlS,
        description: captionController.text,
      );
      captionController.clear();
      setState(() {
        files = [];
        isUploading = false;
        postId = Uuid().v4();
        selected = false;
      });
    }
  
    Scaffold buildUploadForm() {
      return Scaffold(
        appBar: AppBar(
          title: Text(
            "Tu video",
            style: TextStyle(color: Colors.black),
          ),
          actions: [
            FlatButton(
              onPressed: files.length &lt; 2 ? selectImage(context) : null,
              child: Text(
                'Seleccionar otro video',
              ),
            ),
            FlatButton(
              onPressed: isUploading ? null : () =&gt; handleSubmit(),
              child: Text(
                "Mandar",
              ),
            ),
          ],
        ),
        body: ListView.builder(
            scrollDirection: Axis.vertical,
            shrinkWrap: true,
            itemCount: files.length,
            itemBuilder: (BuildContext context, int index) {
              final File fileBuilder = files[index];
              return Container(
                height: 220.0,
                width: MediaQuery.of(context).size.width * 0.8,
                child: Center(
                  child: AspectRatio(
                    aspectRatio: 16 / 9,
                    child: Container(
                      child: ChewieListItem(
                        videoUrl: fileBuilder.path,
                        network: false,
                        file: fileBuilder,
                      ),
                    ),
                  ),
                ),
              );
            }),
      );
    }
  
    Widget buildNormalScreen () {
      return Container(
        child: GestureDetector(
          onTap: () {
            selectImage(context);
          },
          child: Container(
            height: 50.0,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(30.0),
              color: Theme.of(context).accentColor,
            ),
            child: Center(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: &lt;Widget&gt;[
                  Text(
                    'Subir videos',
                    style: TextStyle(
                      fontFamily: 'Comfortaa',
                      fontSize: 17.0,
                      color: Colors.white,
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      );
    }
  
    @override
    Widget build(BuildContext context) {
      return !selected
          ? buildNormalScreen()
          : buildUploadForm();
    }
  }
  </code></pre>
  
  <p>In the function at the top, I also tried doing something like <code>ImagePicker.pickVideo().then((file){...})</code> but it didn't work.
  I also added <code>&lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;</code> to my "android/app/src/main/AndroidManifest.xml" file.
  I also tried adding <code>android:requestLegacyExternalStorage="true"</code> inside the <code>&lt;application&gt;</code> tag in my "android/app/src/main/AndroidManifest.xml" file, but then I get an error:
  <a href="https://i.stack.imgur.com/GcPLQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GcPLQ.png" alt="console printout"></a></p>
  
  <p>I don't know what I should be changing either in my code or in one of the files in the android folder, any help is deeply appreciated.</p>
  
  <p>Thank you very much in advance</p>