From c1d2f4595d5077dd047b9b10ed52f19938bb6457 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 25 Apr 2024 16:06:27 +0300 Subject: [PATCH] feat(chat): Layout Improvements and user avatars load --- .../bloc/chat_select_bloc.dart | 18 +++++-------- .../chat_select_screen.dart | 6 ++--- .../widgets/chat_entry_widget.dart | 25 ++++++++++++++++--- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/lib/presentation/chat/chat_select_screen/bloc/chat_select_bloc.dart b/lib/presentation/chat/chat_select_screen/bloc/chat_select_bloc.dart index a4fa971a..4f95078e 100644 --- a/lib/presentation/chat/chat_select_screen/bloc/chat_select_bloc.dart +++ b/lib/presentation/chat/chat_select_screen/bloc/chat_select_bloc.dart @@ -23,23 +23,17 @@ class ChatSelectBloc extends Bloc { List fillChatEntryList(List chatRooms) { List chats = []; for (int i = 0; i < chatRooms.length; i++) { - String userName; - String userAvatarPath; + String text = chatRooms[i]['last_message']['data']; if (chatRooms[i]['last_message']['is_author_from_user']) { - userName = chatRooms[i]['users']['from_chat_user']['name']; - userAvatarPath = - chatRooms[i]['users']['from_chat_user']['profile_photo_path'] ?? ''; - } else { - userName = chatRooms[i]['users']['to_chat_user']['name']; - userAvatarPath = - chatRooms[i]['users']['to_chat_user']['profile_photo_path'] ?? ''; + text = "Вы: " + text; } chats.add(ChatItemModel( - userImage: userAvatarPath, - username: userName, + userImage: chatRooms[i]['users']['to_chat_user'] + ['profile_photo_path'], + username: chatRooms[i]['users']['to_chat_user']['name'], dateText: DateFormat('dd.MM').format( DateTime.parse(chatRooms[i]['last_message']['updated_at'])), - greetingText: chatRooms[i]['last_message']['data'] ?? '')); + greetingText: text)); } return chats; } diff --git a/lib/presentation/chat/chat_select_screen/chat_select_screen.dart b/lib/presentation/chat/chat_select_screen/chat_select_screen.dart index 3717019a..fdbe8565 100644 --- a/lib/presentation/chat/chat_select_screen/chat_select_screen.dart +++ b/lib/presentation/chat/chat_select_screen/chat_select_screen.dart @@ -47,13 +47,14 @@ class ChatSelectScreen extends StatelessWidget { body: Container( width: double.maxFinite, decoration: AppDecoration.fillGray, - child: Column( + child: ListView( children: [ SizedBox(height: 30.v), Container( margin: EdgeInsets.only( left: 16.h, right: 20.h, + bottom: 10.h, ), padding: EdgeInsets.all(12.h), decoration: BoxDecoration( @@ -77,9 +78,6 @@ class ChatSelectScreen extends StatelessWidget { ), SizedBox(height: 20.v), _buildChatList(context, state), - ElevatedButton( - onPressed: (() => print(state.chatRooms)), - child: Text("asdasd")) ], ), ) diff --git a/lib/presentation/chat/chat_select_screen/widgets/chat_entry_widget.dart b/lib/presentation/chat/chat_select_screen/widgets/chat_entry_widget.dart index ffad0614..36649f13 100644 --- a/lib/presentation/chat/chat_select_screen/widgets/chat_entry_widget.dart +++ b/lib/presentation/chat/chat_select_screen/widgets/chat_entry_widget.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/presentation/chat/chat_select_screen/models/chat_entry.dart'; +import 'package:cached_network_image/cached_network_image.dart'; class UserprofileItemWidget extends StatelessWidget { UserprofileItemWidget(this.userprofileItemModelObj, {Key? key}) @@ -24,7 +25,21 @@ class UserprofileItemWidget extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ - CustomImageView( + CachedNetworkImage( + imageUrl: + dotenv.env['STORAGE_URL']! + userprofileItemModelObj.userImage!, + imageBuilder: (context, imageProvider) => CircleAvatar( + backgroundImage: imageProvider, + radius: 25, + ), + placeholder: (context, url) => CircularProgressIndicator(), + errorWidget: (context, url, error) => CircleAvatar( + child: Icon(Icons.person), + backgroundColor: Colors.white, + radius: 25, + ), + ), + /*CustomImageView( imagePath: dotenv.env['STORAGE_URL']! + userprofileItemModelObj.userImage!, height: 60.adaptSize, @@ -32,7 +47,7 @@ class UserprofileItemWidget extends StatelessWidget { radius: BorderRadius.circular( 30.h, ), - ), + ),*/ Expanded( child: Padding( padding: EdgeInsets.only( @@ -50,7 +65,11 @@ class UserprofileItemWidget extends StatelessWidget { child: Row( children: [ Text( - userprofileItemModelObj.username!, + userprofileItemModelObj.username!.length <= 15 + ? userprofileItemModelObj.username! + : userprofileItemModelObj.username! + .substring(0, 15) + + '...', style: theme.textTheme.titleMedium, ), Spacer(),