2022-02-28 21:26:44 +08:00
|
|
|
import 'package:dash_chat/dash_chat.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hbb/common.dart';
|
2022-03-03 14:58:57 +08:00
|
|
|
import 'package:flutter_hbb/models/chat_model.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2022-03-23 15:28:21 +08:00
|
|
|
import '../models/model.dart';
|
2022-02-28 21:26:44 +08:00
|
|
|
import 'home_page.dart';
|
|
|
|
|
2022-03-03 14:58:57 +08:00
|
|
|
ChatPage chatPage = ChatPage();
|
2022-02-28 21:26:44 +08:00
|
|
|
|
2022-03-03 14:58:57 +08:00
|
|
|
class ChatPage extends StatelessWidget implements PageShape {
|
2022-02-28 21:26:44 +08:00
|
|
|
@override
|
2022-03-23 15:28:21 +08:00
|
|
|
final title = translate("Chat");
|
2022-02-28 21:26:44 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
final icon = Icon(Icons.chat);
|
|
|
|
|
|
|
|
@override
|
2022-03-25 16:34:27 +08:00
|
|
|
final appBarActions = [
|
|
|
|
PopupMenuButton<int>(
|
2022-04-05 00:51:47 +08:00
|
|
|
icon: Icon(Icons.group),
|
2022-03-25 16:34:27 +08:00
|
|
|
itemBuilder: (context) {
|
|
|
|
final chatModel = FFI.chatModel;
|
|
|
|
return chatModel.messages.entries.map((entry) {
|
|
|
|
final id = entry.key;
|
2022-05-16 00:01:27 +08:00
|
|
|
final user = entry.value.chatUser;
|
2022-03-25 16:34:27 +08:00
|
|
|
return PopupMenuItem<int>(
|
2022-04-04 14:54:00 +08:00
|
|
|
child: Text("${user.name} ${user.uid}"),
|
2022-03-25 16:34:27 +08:00
|
|
|
value: id,
|
|
|
|
);
|
|
|
|
}).toList();
|
|
|
|
},
|
|
|
|
onSelected: (id) {
|
|
|
|
FFI.chatModel.changeCurrentID(id);
|
|
|
|
})
|
|
|
|
];
|
2022-02-28 21:26:44 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-03-25 16:34:27 +08:00
|
|
|
return ChangeNotifierProvider.value(
|
|
|
|
value: FFI.chatModel,
|
|
|
|
child: Container(
|
|
|
|
color: MyTheme.grayBg,
|
|
|
|
child: Consumer<ChatModel>(builder: (context, chatModel, child) {
|
2022-04-04 14:54:00 +08:00
|
|
|
final currentUser = chatModel.currentUser;
|
|
|
|
return Stack(
|
|
|
|
children: [
|
|
|
|
DashChat(
|
|
|
|
inputContainerStyle: BoxDecoration(color: Colors.white70),
|
|
|
|
sendOnEnter: false,
|
|
|
|
// if true,reload keyboard everytime,need fix
|
|
|
|
onSend: (chatMsg) {
|
|
|
|
chatModel.send(chatMsg);
|
|
|
|
},
|
|
|
|
user: chatModel.me,
|
2022-05-16 00:01:27 +08:00
|
|
|
messages:
|
|
|
|
chatModel.messages[chatModel.currentID]?.chatMessages ??
|
|
|
|
[],
|
2022-04-04 14:54:00 +08:00
|
|
|
// default scrollToBottom has bug https://github.com/fayeed/dash_chat/issues/53
|
|
|
|
scrollToBottom: false,
|
|
|
|
scrollController: chatModel.scroller,
|
|
|
|
),
|
|
|
|
chatModel.currentID == ChatModel.clientModeID
|
|
|
|
? SizedBox.shrink()
|
|
|
|
: Padding(
|
2022-04-05 00:51:47 +08:00
|
|
|
padding: EdgeInsets.all(12),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Icon(Icons.account_circle,
|
|
|
|
color: MyTheme.accent80),
|
|
|
|
SizedBox(width: 5),
|
|
|
|
Text(
|
|
|
|
"${currentUser.name ?? ""} ${currentUser.uid ?? ""}",
|
|
|
|
style: TextStyle(color: MyTheme.accent50),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)),
|
2022-04-04 14:54:00 +08:00
|
|
|
],
|
2022-03-25 16:34:27 +08:00
|
|
|
);
|
|
|
|
})));
|
2022-03-03 14:58:57 +08:00
|
|
|
}
|
|
|
|
}
|