Skip to content

Commit

Permalink
Merge pull request #177 from kookmin-sw/#173-online-button
Browse files Browse the repository at this point in the history
#173 online button
  • Loading branch information
godeka authored May 6, 2024
2 parents 40663b2 + 7329758 commit 2d66666
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 32 deletions.
4 changes: 4 additions & 0 deletions frontend/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -117,6 +118,9 @@ class _MyAppState extends State<MyApp> {
Provider(
create: (_) => stompClient,
),
ChangeNotifierProvider(
create: (_) => MyCafeModel(),
),
],
child: MaterialApp(
theme: ThemeData(
Expand Down
24 changes: 24 additions & 0 deletions frontend/lib/model/my_cafe_model.dart
Original file line number Diff line number Diff line change
@@ -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();
}
}
72 changes: 44 additions & 28 deletions frontend/lib/screen/cafe_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,6 +42,7 @@ class _CafeDetailsState extends State<CafeDetails>
final places = GoogleMapsPlaces(apiKey: "${dotenv.env['googleApiKey']}");
String photoUrl = '';
List<UserModel>? userList;
late MyCafeModel myCafe;

void _startTimer() {
print("타이머 시작");
Expand Down Expand Up @@ -109,6 +112,7 @@ class _CafeDetailsState extends State<CafeDetails>
stompClient = Provider.of<StompClient>(context);
userList =
Provider.of<Map<String, List<UserModel>>>(context)[widget.cafeId];
myCafe = Provider.of<MyCafeModel>(context);

return Scaffold(
appBar: TopAppBar(
Expand Down Expand Up @@ -189,44 +193,56 @@ class _CafeDetailsState extends State<CafeDetails>
),
),
),
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,
);
},
);
});
},
),
},
),
],
),
);
Expand Down
26 changes: 23 additions & 3 deletions frontend/lib/widgets/button/bottom_two_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,43 @@ 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,
);
}
}

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
Expand All @@ -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),
Expand All @@ -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,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class NotificationDialog extends StatelessWidget {
: BottomTwoButtonsSmall(
first: firstButton,
second: secondButton!,
handleFirstClick: () {},
handleSecondClick: () {},
),
],
),
Expand Down
53 changes: 53 additions & 0 deletions frontend/lib/widgets/dialog/yn_dialog.dart
Original file line number Diff line number Diff line change
@@ -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,
),
],
),
),
);
}
}
4 changes: 3 additions & 1 deletion frontend/lib/widgets/user_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ class ReceivedReqDialog extends StatelessWidget {
),
const ColorTextContainer(text: "# 당신의 업무가 궁금해요."),
const Expanded(child: SizedBox()),
const BottomTwoButtons(
BottomTwoButtons(
first: "수락",
second: "거절",
handleFirstClick: () {},
handleSecondClick: () {},
),
],
),
Expand Down

0 comments on commit 2d66666

Please sign in to comment.