Skip to content

Commit

Permalink
프리뷰 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JerraldKim committed Sep 1, 2024
1 parent 9e45c15 commit 75991e1
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 49 deletions.
20 changes: 12 additions & 8 deletions lib/feature/ImageImporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'dart:io';
final imagePickerServiceProvider = Provider((ref) => ImagePickerService());

final imageFileProvider =
StateNotifierProvider<ImageFileNotifier, File?>((ref) {
StateNotifierProvider<ImageFileNotifier, File?>((ref) {
final imagePickerService = ref.watch(imagePickerServiceProvider);
return ImageFileNotifier(imagePickerService);
});
Expand All @@ -17,7 +17,7 @@ class ImagePickerService {
Future<File?> 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 {
Expand All @@ -33,7 +33,7 @@ class ImagePickerService {
Future<File?> 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 {
Expand All @@ -58,15 +58,19 @@ class ImageFileNotifier extends StateNotifier<File?> {

ImageFileNotifier(this._imagePickerService) : super(null);

Future<void> pickImageFromGallery(BuildContext context) async {
state = await _imagePickerService.pickImageFromGallery(context);
Future<File?> pickImageFromGallery(BuildContext context) async {
final file = await _imagePickerService.pickImageFromGallery(context);
state = file;
return file; // 선택된 파일 return
}

Future<void> pickImageFromCamera(BuildContext context) async {
state = await _imagePickerService.pickImageFromCamera(context);
Future<File?> pickImageFromCamera(BuildContext context) async {
final file = await _imagePickerService.pickImageFromCamera(context);
state = file;
return file; // 선택된 파일 return
}

void clearImage() {
state = null;
}
}
}
141 changes: 100 additions & 41 deletions lib/feature/ProfilePicVerificationScreen.dart
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -144,4 +151,56 @@ class ProfilePicVerificationScreen extends ConsumerWidget {
},
);
}
}

void _showImageConfirmationDialog(

This comment has been minimized.

Copy link
@AlphanoJack

AlphanoJack Sep 1, 2024

Contributor

이부분은 따로 위젯으로 분리 처리하는게 좋을것 같습니다

This comment has been minimized.

Copy link
@JerraldKim

JerraldKim Sep 1, 2024

Author

넵 알겠습니다! 수정 후 PR 올리겠습니다

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('사용'),
),
],
),
],
),
);
},
);
}
}

0 comments on commit 75991e1

Please sign in to comment.