diff --git a/lib/feature/ImageImporter.dart b/lib/feature/ImageImporter.dart index 0cc858a..69e60eb 100644 --- a/lib/feature/ImageImporter.dart +++ b/lib/feature/ImageImporter.dart @@ -6,7 +6,7 @@ import 'dart:io'; final imagePickerServiceProvider = Provider((ref) => ImagePickerService()); final imageFileProvider = - StateNotifierProvider((ref) { +StateNotifierProvider((ref) { final imagePickerService = ref.watch(imagePickerServiceProvider); return ImageFileNotifier(imagePickerService); }); @@ -17,7 +17,7 @@ class ImagePickerService { Future pickImageFromGallery(BuildContext context) async { try { final XFile? pickedFile = - await _picker.pickImage(source: ImageSource.gallery); + await _picker.pickImage(source: ImageSource.gallery); if (pickedFile != null) { return File(pickedFile.path); } else { @@ -33,7 +33,7 @@ class ImagePickerService { Future pickImageFromCamera(BuildContext context) async { try { final XFile? pickedFile = - await _picker.pickImage(source: ImageSource.camera); + await _picker.pickImage(source: ImageSource.camera); if (pickedFile != null) { return File(pickedFile.path); } else { @@ -58,15 +58,19 @@ class ImageFileNotifier extends StateNotifier { ImageFileNotifier(this._imagePickerService) : super(null); - Future pickImageFromGallery(BuildContext context) async { - state = await _imagePickerService.pickImageFromGallery(context); + Future pickImageFromGallery(BuildContext context) async { + final file = await _imagePickerService.pickImageFromGallery(context); + state = file; + return file; // 선택된 파일 return } - Future pickImageFromCamera(BuildContext context) async { - state = await _imagePickerService.pickImageFromCamera(context); + Future pickImageFromCamera(BuildContext context) async { + final file = await _imagePickerService.pickImageFromCamera(context); + state = file; + return file; // 선택된 파일 return } void clearImage() { state = null; } -} +} \ No newline at end of file diff --git a/lib/feature/ProfilePicVerificationScreen.dart b/lib/feature/ProfilePicVerificationScreen.dart index c224338..203d3d2 100644 --- a/lib/feature/ProfilePicVerificationScreen.dart +++ b/lib/feature/ProfilePicVerificationScreen.dart @@ -1,10 +1,11 @@ +import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'ImageImporter.dart'; class ProfilePicVerificationScreen extends ConsumerWidget { const ProfilePicVerificationScreen({super.key}); - static const name = 'ProfilePicverificationScreen'; + static const name = 'ProfilePicVerificationScreen'; @override Widget build(BuildContext context, WidgetRef ref) { @@ -41,44 +42,44 @@ class ProfilePicVerificationScreen extends ConsumerWidget { ), child: imageFile != null ? ClipRRect( - borderRadius: BorderRadius.circular(20.0), - child: Stack( - children: [ - Image.file( - imageFile, - fit: BoxFit.cover, - width: squareSize, - height: squareSize, - color: isAuthorized - ? null - : Colors.black.withOpacity(0.6), - colorBlendMode: - isAuthorized ? null : BlendMode.darken, + borderRadius: BorderRadius.circular(20.0), + child: Stack( + children: [ + Image.file( + imageFile, + fit: BoxFit.cover, + width: squareSize, + height: squareSize, + color: isAuthorized + ? null + : Colors.black.withOpacity(0.6), + colorBlendMode: + isAuthorized ? null : BlendMode.darken, + ), + if (!isAuthorized) + Center( + child: Text( + '승인 대기 중입니다 \n조금만 기다려주세요', + style: TextStyle( + color: Colors.white, + fontSize: 24, + fontWeight: FontWeight.bold, + backgroundColor: + Colors.black.withOpacity(0.5), ), - if (!isAuthorized) - Center( - child: Text( - '승인 대기 중입니다 \n조금만 기다려주세요', - style: TextStyle( - color: Colors.white, - fontSize: 24, - fontWeight: FontWeight.bold, - backgroundColor: - Colors.black.withOpacity(0.5), - ), - textAlign: TextAlign.center, - ), - ), - ], + textAlign: TextAlign.center, + ), ), - ) + ], + ), + ) : const Center( - child: Icon( - Icons.pets, - size: 200, - color: Colors.white, - ), - ), + child: Icon( + Icons.pets, + size: 200, + color: Colors.white, + ), + ), ), const SizedBox(height: 20), ElevatedButton( @@ -113,20 +114,26 @@ class ProfilePicVerificationScreen extends ConsumerWidget { leading: const Icon(Icons.photo_library), title: const Text('갤러리에서 선택'), onTap: () async { - await ref + final file = await ref .read(imageFileProvider.notifier) - .pickImageFromGallery(context); + .pickImageFromGallery(context); // 선택된 파일 캡처 Navigator.of(context).pop(); + if (file != null) { + _showImageConfirmationDialog(context, file, ref); + } }, ), ListTile( leading: const Icon(Icons.camera_alt), title: const Text('카메라로 찍기'), onTap: () async { - await ref + final file = await ref .read(imageFileProvider.notifier) - .pickImageFromCamera(context); + .pickImageFromCamera(context); // 선택된 파일 캡처 Navigator.of(context).pop(); + if (file != null) { + _showImageConfirmationDialog(context, file, ref); + } }, ), if (ref.read(imageFileProvider) != null) @@ -144,4 +151,56 @@ class ProfilePicVerificationScreen extends ConsumerWidget { }, ); } -} + + void _showImageConfirmationDialog( + BuildContext context, File imageFile, WidgetRef ref) { + showDialog( + context: context, + builder: (BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Image.file( + imageFile, + fit: BoxFit.cover, + ), + Padding( + padding: const EdgeInsets.all(16.0), + child: Text( + '이 사진을 사용하시겠습니까?', + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + ElevatedButton( + onPressed: () { + Navigator.of(context).pop(); + ref.read(imageFileProvider.notifier).clearImage(); + }, + child: Text('다시 선택'), + ), + ElevatedButton( + onPressed: () { + Navigator.of(context).pop(); + ref.read(imageFileProvider.notifier).state = imageFile; + }, + child: Text('사용'), + ), + ], + ), + ], + ), + ); + }, + ); + } +} \ No newline at end of file