forked from eatvio/eatvio_app
feat(chat): add init and dispose chat, typing info, receive a messages
This commit is contained in:
@@ -19,6 +19,8 @@ class ChatScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ChatScreenState extends State<ChatScreen> {
|
||||
final scrollController = ScrollController();
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<ChatRoomCubit>(
|
||||
create: (BuildContext context) => sl()..initChat(widget.chatId),
|
||||
@@ -33,7 +35,12 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
} else if (state is ChatRoomStateLoaded) {
|
||||
return _buildChat(context, state);
|
||||
} else if (state is ChatRoomStateError) {
|
||||
return Center(child: Text(state.errorMessage));
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: Text(state.errorMessage),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
@@ -46,6 +53,16 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void setupScrollController(BuildContext context) {
|
||||
scrollController.addListener(() {
|
||||
if (scrollController.position.atEdge) {
|
||||
if (scrollController.position.pixels != 0) {
|
||||
context.read<ChatRoomCubit>();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_buildChat(BuildContext context, ChatRoomStateLoaded state) {
|
||||
mediaQueryData = MediaQuery.of(context);
|
||||
return Scaffold(
|
||||
@@ -68,7 +85,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Text(
|
||||
state.chatRoomModel.users['to_chat_user']!.name.split(' ').first[0] + state.chatRoomModel.users['to_chat_user']!.name.split(' ')[1][0],
|
||||
state.chatRoom.users['to_chat_user']!.name.split(' ').first[0] + state.chatRoom.users['to_chat_user']!.name.split(' ')[1][0],
|
||||
style: TextStyle(
|
||||
color: Color(0xFF7F9CF5),
|
||||
fontWeight: FontWeight.w400,
|
||||
@@ -77,11 +94,27 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
),
|
||||
),
|
||||
SizedBox(width: 16),
|
||||
Text(
|
||||
state.chatRoomModel.users['to_chat_user']!.name,
|
||||
style: CustomTextStyles.titleSmallBold.copyWith(
|
||||
color: PrimaryColors().blueGray800,
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
state.chatRoom.users['to_chat_user']!.name,
|
||||
style: CustomTextStyles.titleSmallBold.copyWith(
|
||||
color: PrimaryColors().blueGray800,
|
||||
),
|
||||
),
|
||||
AnimatedCrossFade(
|
||||
firstChild: Text(
|
||||
'Печатает...',
|
||||
style: CustomTextStyles.bodySmallMulishPrimary,
|
||||
),
|
||||
firstCurve: Curves.easeIn,
|
||||
secondCurve: Curves.easeOut,
|
||||
secondChild: const SizedBox.shrink(),
|
||||
crossFadeState: state.isTyping ? CrossFadeState.showFirst : CrossFadeState.showSecond,
|
||||
duration: Duration(milliseconds: 150),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -95,6 +128,8 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
color: Color(0xFFF0F2F5),
|
||||
width: double.maxFinite,
|
||||
child: CustomScrollView(
|
||||
physics: BouncingScrollPhysics(),
|
||||
controller: scrollController,
|
||||
reverse: true,
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
@@ -102,12 +137,11 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) => ChatBubbleWidget(
|
||||
text: state.chatRoomModel.messages[state.chatRoomModel.messages.length - index - 1].data,
|
||||
isCurrentUser: state.chatRoomModel.users['to_chat_user']!.id !=
|
||||
state.chatRoomModel.messages[state.chatRoomModel.messages.length - index - 1].authorId,
|
||||
mediaData: state.chatRoomModel.messages[state.chatRoomModel.messages.length - index - 1].mediaData,
|
||||
text: state.chatMessages.messagesList[index].data.trim(),
|
||||
isCurrentUser: state.chatRoom.users['to_chat_user']!.id != state.chatMessages.messagesList[index].authorId,
|
||||
mediaData: state.chatMessages.messagesList[index].mediaData ?? [],
|
||||
),
|
||||
childCount: state.chatRoomModel.messages.length,
|
||||
childCount: state.chatMessages.messagesList.length,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -80,7 +80,7 @@ class ChatEntryWidget extends StatelessWidget {
|
||||
),
|
||||
SizedBox(height: 6.v),
|
||||
Text(
|
||||
chatEntryObj.greetingText!,
|
||||
chatEntryObj.greetingText!.trim(),
|
||||
style: CustomTextStyles.bodyMediumBluegray800,
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user