Flutter android emulator Select video from Camera by image_picker

35 Views Asked by At

I use same code with this website https://www.geeksforgeeks.org/how-to-select-video-from-camera-and-gallery-in-flutter/ in my android emulator,Screenshot, but it always show nothing is selected, i add some debugging code on getVideo method, print null

  Future getVideo(
    ImageSource img,
  ) async {
    final pickedFile = await picker.pickVideo(
        source: img,
        preferredCameraDevice: CameraDevice.front,
        maxDuration: const Duration(minutes: 10));
    XFile? xfilePick = pickedFile;
    setState(
      () {
        if (xfilePick != null) {
          galleryFile = File(pickedFile!.path);
        } else {
          ScaffoldMessenger.of(context).showSnackBar(// is this context <<<
              const SnackBar(content: Text('Nothing is selected')));
        }
      },
    );
    print("================");
    print(pickedFile == null);
    print("================");
  }
Do anyone know the reason?
Dart: 2.18.0 
image_picker: ^0.8.6+1 
cupertino_icons: ^1.0.2

I have add these 2 lines in android/app/src/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.graphic_ai">
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
   <application

To ensure the right, But still not work,

0

There are 0 best solutions below