diff --git a/lib/models/camera_response.dart b/lib/models/camera_response.dart index 3552488..b5e4d5d 100644 --- a/lib/models/camera_response.dart +++ b/lib/models/camera_response.dart @@ -7,7 +7,11 @@ class CameraResponse { CameraResponse({this.liquors, this.size}); CameraResponse.fromJson(Map json) { - if (json['liquors'] != null) { // liquors가 null이 아니면 + if(json['size']==0) { + liquors = []; + size = 0; + } + if (json['liquors'] != null && json['size']!=0) { // liquors가 null이 아니면 liquors = []; // 배열? 선언 json['liquors'].forEach((v) { // 들어있는거마다 담아! liquors!.add(CameraLiquor.fromJson(v)); diff --git a/lib/screens/camera/camera_screen.dart b/lib/screens/camera/camera_screen.dart index 2d1d815..33a8dd4 100644 --- a/lib/screens/camera/camera_screen.dart +++ b/lib/screens/camera/camera_screen.dart @@ -60,9 +60,10 @@ class CameraScreenState extends State { progressDialog.show(max:100, msg: '사진을 분석 중입니다...', completed: Completed(completedMsg: '찾았다!', closedDelay: 2000)); final yoloResponse = await yoloDio.post(yoloServerPath, data: imageFormData); /// YOLO 서버에 이미지 전송 progressDialog.close(); /// 진행 중 화면 닫기 + Map responseMap = yoloResponse.data; /// 결과를 Map에 담고(type casting) final parsedYoloResponse = CameraResponse.fromJson(responseMap); /// Map을 OneResponse로 바꿈 - + print("Tlqkf-after"); if (parsedYoloResponse.size! > 1) { /// 여러 개일 때 선택받아야함 await _showChoiceDialog(context, liquors: parsedYoloResponse.liquors!); } else if (parsedYoloResponse.size! == 1) { /// 1개일 때는 다이렉트 이동 @@ -75,7 +76,23 @@ class CameraScreenState extends State { ) ); } else { // 에러 처리 필요 - + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: Text("인식에 실패했습니다."), + content: Text("다시 한번 찍어보세요"), + actions: [ + ElevatedButton( + child: Text("예"), + onPressed: () { + Navigator.of(context).pop(); + }, + ) + ], + ); + } + ); } } catch (e) { print(e); @@ -119,8 +136,24 @@ class CameraScreenState extends State { Future _createImageToHttpForm({required String key, required XFile image}) async => FormData.fromMap({key: await MultipartFile.fromFile(image.path)}); + Future _showEmptyDialog(BuildContext context) async { + return showDialog( + context: context, + builder: (BuildContext context) => + AlertDialog( + title: const Text("술 인식이 1개도 안 됐어요"), + content: const Text("다시 찍어보세요"), + actions: [ + ElevatedButton(onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('예')), + ], + ), + ); + } - /// 팝업 보여주는 함수 + /// 선택 팝업 보여주는 함수 Future _showChoiceDialog(BuildContext context, {required List liquors}) async { return showDialog( context: context, @@ -177,7 +210,6 @@ class CameraScreenState extends State { ) ); } - }