Skip to content

Commit

Permalink
Merge pull request #208 from kookmin-sw/bug/fe/#197-fixBug
Browse files Browse the repository at this point in the history
Bug/fe/#197 fix bug
  • Loading branch information
kevinmj12 authored May 15, 2024
2 parents feb8cbc + af31f9f commit d6f0922
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:capstone_front/utils/basic_button.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:go_router/go_router.dart';

class HelperDetailScreen extends StatefulWidget {
Expand All @@ -25,13 +26,22 @@ class HelperDetailScreen extends StatefulWidget {
class _HelperDetailScreenState extends State<HelperDetailScreen> {
late HelperArticleModel helperArticleModel;
bool isLoading = true;
bool isMyArticle = true;

void loadDetail() async {
FlutterSecureStorage storage = const FlutterSecureStorage();
helperArticleModel =
await HelperService.getDetailById(widget.helperArticlePreviewModel.id);
setState(() {
isLoading = false;
});
final uuid = await storage.read(key: "uuid");
print(uuid);
print(helperArticleModel.uuid);
if (uuid != helperArticleModel.uuid) {
isMyArticle = false;
}
setState(() {});
}

@override
Expand Down Expand Up @@ -111,15 +121,18 @@ class _HelperDetailScreenState extends State<HelperDetailScreen> {
const SizedBox(
height: 20,
),
BasicButton(
text: tr('helper.start_chat'),
onPressed: () {
var chatInitModel = ChatInitModel.fromJson({
'author': widget.helperArticlePreviewModel.author,
'uuid': helperArticleModel.uuid,
});
context.push("/chatroom", extra: chatInitModel);
})
isMyArticle
? const SizedBox.shrink()
: BasicButton(
text: tr('helper.start_chat'),
onPressed: () {
var chatInitModel = ChatInitModel.fromJson({
'author': widget.helperArticlePreviewModel.author,
'uuid': helperArticleModel.uuid,
});
context.push("/chatroom", extra: chatInitModel);
},
)
],
),
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ class _HelperChattingCardState extends State<HelperChattingCard> {

Future<void> initInitialState() async {
var chatHistory = await loadChatData(widget.chatRoomModel.userId);
setState(() {
lastMessageId = chatHistory.last.id;
});
if (chatHistory.isNotEmpty) {
setState(() {
lastMessageId = chatHistory.last.id;
});
}
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ class _HelperChattingListScreenState extends State<HelperChattingListScreen> {
Future<void> startPolling(Map<String, dynamic> roomInfo) async {
try {
while (isActive) {
// loadChatRooms();
try {
var currentNewChatsInfos =
await ChatService.pollingChatList(roomInfo);
print('roominfo');
print(roomInfo);
for (var newChatInfo in currentNewChatsInfos) {
var flag = true; // 새로운 채팅방인지 아닌지 확인
for (var chatRoom in chatRoomList) {
Expand All @@ -67,15 +64,17 @@ class _HelperChattingListScreenState extends State<HelperChattingListScreen> {

if (flag) {
// 새로운 채팅방일 때
chatRoomList.add(ChatRoomModel(
chatRoomId: newChatInfo.chatRoomId,
userId: newChatInfo.userId,
userName: newChatInfo.userId,
lastMessageId: 0,
lastMessagePreviewId: newChatInfo.id,
chatRoomMessage: newChatInfo.content,
chatRoomDate: newChatInfo.timestamp,
));
if (newChatInfo.id != 0) {
chatRoomList.add(ChatRoomModel(
chatRoomId: newChatInfo.chatRoomId,
userId: newChatInfo.userId,
userName: newChatInfo.userId,
lastMessageId: 0,
lastMessagePreviewId: newChatInfo.id,
chatRoomMessage: newChatInfo.content,
chatRoomDate: newChatInfo.timestamp,
));
}
}
}

Expand Down Expand Up @@ -117,13 +116,17 @@ class _HelperChattingListScreenState extends State<HelperChattingListScreen> {
body: ListView.builder(
itemCount: chatRoomList.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: HelperChattingCard(
chatRoomModel: chatRoomList[index],
chatRoomListUpdate: loadChatRooms,
),
);
if (chatRoomList[index].lastMessageId != 0) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: HelperChattingCard(
chatRoomModel: chatRoomList[index],
chatRoomListUpdate: loadChatRooms,
),
);
} else {
return const SizedBox.shrink();
}
},
),
);
Expand Down

0 comments on commit d6f0922

Please sign in to comment.