diff --git a/frontend/lib/main.dart b/frontend/lib/main.dart index 85a996b598..74918b9495 100644 --- a/frontend/lib/main.dart +++ b/frontend/lib/main.dart @@ -10,6 +10,7 @@ import 'package:frontend/screen/chatroom_list_screen.dart'; import 'package:frontend/screen/chat_screen.dart'; import 'package:frontend/screen/search_company_screen.dart'; import 'package:frontend/model/user_model.dart'; +import 'package:frontend/model/my_cafe_model.dart'; import 'package:frontend/screen/coffeechat_req_list.dart'; import 'package:frontend/screen/map_place.dart'; import 'package:frontend/screen/signup_screen.dart'; @@ -117,6 +118,9 @@ class _MyAppState extends State { Provider( create: (_) => stompClient, ), + ChangeNotifierProvider( + create: (_) => MyCafeModel(), + ), ], child: MaterialApp( theme: ThemeData( diff --git a/frontend/lib/model/my_cafe_model.dart b/frontend/lib/model/my_cafe_model.dart new file mode 100644 index 0000000000..4a10bae872 --- /dev/null +++ b/frontend/lib/model/my_cafe_model.dart @@ -0,0 +1,24 @@ +import 'package:flutter/material.dart'; + +class MyCafeModel extends ChangeNotifier { + String? cafeId; + String? latitude; + String? longitude; + + MyCafeModel({ + this.cafeId, + this.latitude, + this.longitude, + }); + + void setMyCafe({ + required String cafeId, + required String latitude, + required String longitude, + }) { + this.cafeId = cafeId; + this.latitude = latitude; + this.longitude = longitude; + notifyListeners(); + } +} diff --git a/frontend/lib/screen/cafe_details.dart b/frontend/lib/screen/cafe_details.dart index 574a63fed9..906ef658d7 100644 --- a/frontend/lib/screen/cafe_details.dart +++ b/frontend/lib/screen/cafe_details.dart @@ -8,7 +8,9 @@ import 'package:frontend/widgets/cafe_info.dart'; import 'package:frontend/widgets/top_appbar.dart'; import 'package:frontend/widgets/user_item.dart'; import 'package:frontend/widgets/button/bottom_text_button.dart'; +import 'package:frontend/widgets/dialog/yn_dialog.dart'; import 'package:frontend/model/user_model.dart'; +import 'package:frontend/model/my_cafe_model.dart'; import 'package:geolocator/geolocator.dart'; import 'package:google_maps_webservice/places.dart'; import 'package:latlong2/latlong.dart' as latlong2; @@ -40,6 +42,7 @@ class _CafeDetailsState extends State final places = GoogleMapsPlaces(apiKey: "${dotenv.env['googleApiKey']}"); String photoUrl = ''; List? userList; + late MyCafeModel myCafe; void _startTimer() { print("타이머 시작"); @@ -109,6 +112,7 @@ class _CafeDetailsState extends State stompClient = Provider.of(context); userList = Provider.of>>(context)[widget.cafeId]; + myCafe = Provider.of(context); return Scaffold( appBar: TopAppBar( @@ -189,44 +193,56 @@ class _CafeDetailsState extends State ), ), ), - BottomTextButton( - text: "이 카페를 내 위치로 지정하기", - handlePressed: () { - _startTimer(); - - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: const Text("카페 지정"), - content: Text("${widget.cafeName}을(를) 내 위치로 지정하겠습니까?"), - actions: [ - TextButton( - onPressed: () { + (myCafe.cafeId == widget.cafeId) + ? Container() + : BottomTextButton( + text: "이 카페를 내 위치로 지정하기", + handlePressed: () { + _startTimer(); + + showDialog( + context: context, + builder: (context) { + bool setOrChange = myCafe.cafeId == null ? true : false; + String content = setOrChange + ? "${widget.cafeName}을(를) 내 위치로 표시하겠습니까?" + : "${widget.cafeName}을(를) 내 위치로 표시하도록 변경하겠습니까?"; + + return YesOrNoDialog( + content: content, + firstButton: "확인", + secondButton: "취소", + handleFirstClick: () { _stopTimer(); - Navigator.pop(context); + // 지정 카페 변경인 경우 + if (!setOrChange) { + // 기존 카페에서 유저 삭제 pub 요청 + deleteUserInCafe( + stompClient, + "test", + myCafe.cafeId!, + ); + } // 카페에 유저 추가 pub 요청 addUserInCafe( stompClient, "test", widget.cafeId, ); + + myCafe.setMyCafe( + cafeId: widget.cafeId, + latitude: widget.cafeDetailsArguments[6], + longitude: widget.cafeDetailsArguments[7], + ); }, - child: const Text("확인"), - ), - TextButton( - onPressed: () { - _stopTimer(); - Navigator.pop(context); - }, - child: const Text("취소"), - ), - ], + handleSecondClick: _stopTimer, + ); + }, ); - }); - }, - ), + }, + ), ], ), ); diff --git a/frontend/lib/widgets/button/bottom_two_buttons.dart b/frontend/lib/widgets/button/bottom_two_buttons.dart index dc19d95cc2..0d8c4eb633 100644 --- a/frontend/lib/widgets/button/bottom_two_buttons.dart +++ b/frontend/lib/widgets/button/bottom_two_buttons.dart @@ -3,16 +3,26 @@ import 'package:flutter/material.dart'; class BottomTwoButtonsSmall extends StatelessWidget { final String first; final String second; + final Function handleFirstClick; + final Function handleSecondClick; const BottomTwoButtonsSmall({ super.key, required this.first, required this.second, + required this.handleFirstClick, + required this.handleSecondClick, }); @override Widget build(BuildContext context) { - return BottomTwoButtons(width: 110, first: first, second: second); + return BottomTwoButtons( + width: 110, + first: first, + second: second, + handleFirstClick: handleFirstClick, + handleSecondClick: handleSecondClick, + ); } } @@ -20,12 +30,16 @@ class BottomTwoButtons extends StatelessWidget { final double? width; final String first; final String second; + final Function handleFirstClick; + final Function handleSecondClick; const BottomTwoButtons({ super.key, this.width = 130, required this.first, required this.second, + required this.handleFirstClick, + required this.handleSecondClick, }); @override @@ -37,7 +51,10 @@ class BottomTwoButtons extends StatelessWidget { width: width, height: 50, child: ElevatedButton( - onPressed: () {}, + onPressed: () { + Navigator.pop(context); + handleFirstClick(); + }, style: ElevatedButton.styleFrom( foregroundColor: Colors.white, backgroundColor: const Color(0xff212121), @@ -52,7 +69,10 @@ class BottomTwoButtons extends StatelessWidget { width: width, height: 50, child: TextButton( - onPressed: () {}, + onPressed: () { + Navigator.pop(context); + handleSecondClick(); + }, style: TextButton.styleFrom( foregroundColor: Colors.black, ), diff --git a/frontend/lib/widgets/notification_dialog.dart b/frontend/lib/widgets/dialog/notification_dialog.dart similarity index 98% rename from frontend/lib/widgets/notification_dialog.dart rename to frontend/lib/widgets/dialog/notification_dialog.dart index 4226de3a9c..1bdb8f9fba 100644 --- a/frontend/lib/widgets/notification_dialog.dart +++ b/frontend/lib/widgets/dialog/notification_dialog.dart @@ -104,6 +104,8 @@ class NotificationDialog extends StatelessWidget { : BottomTwoButtonsSmall( first: firstButton, second: secondButton!, + handleFirstClick: () {}, + handleSecondClick: () {}, ), ], ), diff --git a/frontend/lib/widgets/dialog/yn_dialog.dart b/frontend/lib/widgets/dialog/yn_dialog.dart new file mode 100644 index 0000000000..107958f8c0 --- /dev/null +++ b/frontend/lib/widgets/dialog/yn_dialog.dart @@ -0,0 +1,53 @@ +import 'package:flutter/material.dart'; +import 'package:frontend/widgets/button/bottom_two_buttons.dart'; + +class YesOrNoDialog extends StatelessWidget { + final String content; + final String firstButton; + final String secondButton; + final Function handleFirstClick; + final Function handleSecondClick; + + const YesOrNoDialog({ + super.key, + required this.content, + required this.firstButton, + required this.secondButton, + required this.handleFirstClick, + required this.handleSecondClick, + }); + + @override + Widget build(BuildContext context) { + return Dialog( + backgroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20), + ), + child: Container( + padding: const EdgeInsets.all(20), + width: 300, + height: 200, + child: Column( + children: [ + const SizedBox( + height: 15, + ), + Text( + content, + textAlign: TextAlign.center, + style: const TextStyle(fontSize: 20), + ), + const Expanded(child: SizedBox()), + BottomTwoButtonsSmall( + first: "확인", + second: "취소", + handleFirstClick: handleFirstClick, + handleSecondClick: handleSecondClick, + ), + ], + ), + ), + ); + } +} diff --git a/frontend/lib/widgets/user_item.dart b/frontend/lib/widgets/user_item.dart index 2b0ce6fddb..5fdb9f8a50 100644 --- a/frontend/lib/widgets/user_item.dart +++ b/frontend/lib/widgets/user_item.dart @@ -163,9 +163,11 @@ class ReceivedReqDialog extends StatelessWidget { ), const ColorTextContainer(text: "# 당신의 업무가 궁금해요."), const Expanded(child: SizedBox()), - const BottomTwoButtons( + BottomTwoButtons( first: "수락", second: "거절", + handleFirstClick: () {}, + handleSecondClick: () {}, ), ], ),