mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Can take videos
This commit is contained in:
		@@ -14,6 +14,8 @@
 | 
			
		||||
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
 | 
			
		||||
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
 | 
			
		||||
 | 
			
		||||
    <!-- Fix camera issue -->
 | 
			
		||||
    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
 | 
			
		||||
 | 
			
		||||
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
 | 
			
		||||
         calls FlutterMain.startInitialization(this); in its onCreate method.
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,8 @@ import 'package:mime/mime.dart';
 | 
			
		||||
enum _FileChoices {
 | 
			
		||||
  PICK_IMAGE,
 | 
			
		||||
  TAKE_PICTURE,
 | 
			
		||||
  PICK_VIDEO,
 | 
			
		||||
  TAKE_VIDEO,
 | 
			
		||||
  PICK_OTHER_FILE,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -43,18 +45,32 @@ List<_PickFileOption> get _optionsList => [
 | 
			
		||||
      _PickFileOption(
 | 
			
		||||
          value: _FileChoices.PICK_IMAGE,
 | 
			
		||||
          label: tr("Choose an image"),
 | 
			
		||||
          icon: Icons.image_search,
 | 
			
		||||
          icon: Icons.image,
 | 
			
		||||
          canEnable: (l) => l.any(isImage)),
 | 
			
		||||
      _PickFileOption(
 | 
			
		||||
          value: _FileChoices.TAKE_PICTURE,
 | 
			
		||||
          label: tr("Take a picture"),
 | 
			
		||||
          icon: Icons.camera_alt,
 | 
			
		||||
          canEnable: (l) => l.any(isImage)),
 | 
			
		||||
 | 
			
		||||
      // Video
 | 
			
		||||
      _PickFileOption(
 | 
			
		||||
          value: _FileChoices.PICK_VIDEO,
 | 
			
		||||
          label: tr("Choose a video"),
 | 
			
		||||
          icon: Icons.video_library,
 | 
			
		||||
          canEnable: (l) => l.any(isVideo)),
 | 
			
		||||
      _PickFileOption(
 | 
			
		||||
          value: _FileChoices.TAKE_VIDEO,
 | 
			
		||||
          label: tr("Take a video"),
 | 
			
		||||
          icon: Icons.videocam,
 | 
			
		||||
          canEnable: (l) => l.any(isVideo)),
 | 
			
		||||
 | 
			
		||||
      // Other
 | 
			
		||||
      _PickFileOption(
 | 
			
		||||
          value: _FileChoices.PICK_OTHER_FILE,
 | 
			
		||||
          label: tr("Browse files"),
 | 
			
		||||
          icon: Icons.folder_open,
 | 
			
		||||
          canEnable: (l) => l.any((el) => !isImage(el))),
 | 
			
		||||
          canEnable: (l) => l.any((el) => !isImage(el) && !isVideo(el))),
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
Future<BytesFile> showPickFileDialog({
 | 
			
		||||
@@ -107,6 +123,21 @@ Future<BytesFile> showPickFileDialog({
 | 
			
		||||
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    // Pick an video
 | 
			
		||||
    case _FileChoices.PICK_VIDEO:
 | 
			
		||||
    case _FileChoices.TAKE_VIDEO:
 | 
			
		||||
      final image = await ImagePicker().getVideo(
 | 
			
		||||
        source: choice == _FileChoices.PICK_VIDEO
 | 
			
		||||
            ? ImageSource.gallery
 | 
			
		||||
            : ImageSource.camera,
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      if (image == null) return null;
 | 
			
		||||
 | 
			
		||||
      file = BytesFile(image.path.split("/").last, await image.readAsBytes());
 | 
			
		||||
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    // Pick other files
 | 
			
		||||
    case _FileChoices.PICK_OTHER_FILE:
 | 
			
		||||
      final pickedFile = await FilePicker.platform.pickFiles(
 | 
			
		||||
 
 | 
			
		||||
@@ -48,3 +48,6 @@ Future<PickedFile> pickImage(BuildContext context) async {
 | 
			
		||||
 | 
			
		||||
/// Check if a mime type maps to an image or not
 | 
			
		||||
bool isImage(String mimeType) => mimeType.startsWith("image/");
 | 
			
		||||
 | 
			
		||||
/// Check if a mime type maps to an image or not
 | 
			
		||||
bool isVideo(String mimeType) => mimeType.startsWith("video/mp4");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user