From 887a1f4ded786a6dbf231e6e7916a72e5310a7d9 Mon Sep 17 00:00:00 2001 From: Xin Yao Date: Tue, 20 Jul 2021 12:38:59 -0700 Subject: [PATCH] Show dialog to choose Photo or Video when clicking camera button --- lib/src/widgets/toolbar/camera_button.dart | 32 ++++++++++++++++++- .../widgets/toolbar/image_video_utils.dart | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/src/widgets/toolbar/camera_button.dart b/lib/src/widgets/toolbar/camera_button.dart index 099700f3..9c4f2d0d 100644 --- a/lib/src/widgets/toolbar/camera_button.dart +++ b/lib/src/widgets/toolbar/camera_button.dart @@ -63,7 +63,37 @@ class CameraButton extends StatelessWidget { FilePickImpl? filePickImpl, WebImagePickImpl? webImagePickImpl}) async { if (onImagePickCallback != null && onVideoPickCallback != null) { - // TODO: show dialog to choose Image or Video + // Show dialog to choose Photo or Video + return await showDialog( + context: context, + builder: (context) { + return AlertDialog( + contentPadding: const EdgeInsets.all(0), + backgroundColor: Colors.transparent, + content: Column(mainAxisSize: MainAxisSize.min, children: [ + TextButton.icon( + icon: const Icon(Icons.photo, color: Colors.cyanAccent), + label: const Text('Photo'), + onPressed: () { + ImageVideoUtils.handleImageButtonTap(context, controller, + ImageSource.camera, onImagePickCallback, + filePickImpl: filePickImpl, + webImagePickImpl: webImagePickImpl); + }, + ), + TextButton.icon( + icon: const Icon(Icons.movie_creation, + color: Colors.orangeAccent), + label: const Text('Video'), + onPressed: () { + ImageVideoUtils.handleVideoButtonTap(context, controller, + ImageSource.camera, onVideoPickCallback, + filePickImpl: filePickImpl, + webVideoPickImpl: webVideoPickImpl); + }, + ) + ])); + }); } if (onImagePickCallback != null) { diff --git a/lib/src/widgets/toolbar/image_video_utils.dart b/lib/src/widgets/toolbar/image_video_utils.dart index 6f044d0d..074e2898 100644 --- a/lib/src/widgets/toolbar/image_video_utils.dart +++ b/lib/src/widgets/toolbar/image_video_utils.dart @@ -80,7 +80,7 @@ class ImageVideoUtils { '(check out example directory for how to do it)'); videoUrl = await webVideoPickImpl!(onVideoPickCallback); } else if (Platform.isAndroid || Platform.isIOS) { - videoUrl = await _pickVideo(ImageSource.gallery, onVideoPickCallback); + videoUrl = await _pickVideo(videoSource, onVideoPickCallback); } else { assert(filePickImpl != null, 'Desktop must provide filePickImpl'); videoUrl =