From 9e0ccb577369e941dee9256cf7ab40d84a161068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=B1=A0=E4=BF=8A=E8=BC=94?= Date: Mon, 24 Jul 2023 18:49:15 +0900 Subject: [PATCH] =?UTF-8?q?=E7=94=BB=E5=83=8F=E3=81=8C=E9=81=B8=E6=8A=9E?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E6=99=82?= =?UTF-8?q?=E3=81=AB=E4=BE=8B=E5=A4=96=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=8F?= =?UTF-8?q?null=E3=82=92=E8=BF=94=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../image_pick/image_pick_function.dart | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/packages/mottai_flutter_app/lib/development/image_pick/image_pick_function.dart b/packages/mottai_flutter_app/lib/development/image_pick/image_pick_function.dart index 2918bd71..0328facd 100644 --- a/packages/mottai_flutter_app/lib/development/image_pick/image_pick_function.dart +++ b/packages/mottai_flutter_app/lib/development/image_pick/image_pick_function.dart @@ -1,29 +1,37 @@ +// ignore_for_file: avoid_catches_without_on_clauses + import 'dart:io'; import 'package:image_picker/image_picker.dart'; - enum PickType { camera, gallery, } + final ImagePicker _picker = ImagePicker(); ///一枚のみ選択する場合 ///写真を撮影するか選択するかはenumのPickTypeで渡す -Future fetchSingleImage(PickType pickType) async { - final _imageFile = await _picker.pickImage( - source: - pickType == PickType.camera ? ImageSource.camera : ImageSource.gallery, - ); - if (_imageFile == null) { - throw Exception('画像が選択されませんでした。'); +Future fetchSingleImage(PickType pickType) async { + try { + final _imageFile = await _picker.pickImage( + source: pickType == PickType.camera + ? ImageSource.camera + : ImageSource.gallery, + ); + return _imageFile == null ? null : File(_imageFile.path); + } catch (e) { + return null; } - return File(_imageFile.path); } ///複数選択する場合 Future> fetchMultipleImage() async { - final _imageFiles = await _picker.pickMultiImage(); - return _imageFiles.map((e) => File(e.path)).toList(); + try { + final _imageFiles = await _picker.pickMultiImage(); + return _imageFiles.map((e) => File(e.path)).toList(); + } catch (e) { + return []; + } }