From 5028a3b860c6786fc9bad7df09bad0a81dcb2949 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Wed, 28 Dec 2022 10:16:15 +0300 Subject: [PATCH] App Bar online / Offline & Fixes --- lib/provider/chat_provider_model.dart | 19 ++- lib/ui/chat/chat_detailed_screen.dart | 1 - lib/ui/chat/chat_home_screen.dart | 2 + .../search_employee_bottom_sheet.dart | 2 + lib/widgets/chat_app_bar_widge.dart | 113 ++++++++++-------- 5 files changed, 79 insertions(+), 58 deletions(-) diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index b4bd451..0851392 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -175,9 +175,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { if (response.statusCode == 204) { if (isNewChat) { userChatHistory = []; - } else if (loadMore) { - - } + } else if (loadMore) {} } else { if (loadMore) { List temp = getSingleUserChatModel(response.body).reversed.toList(); @@ -933,7 +931,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { return f.format(data); } - Future favoriteUser({required int userID, required int targetUserID}) async { + Future favoriteUser({required int userID, required int targetUserID, required bool fromSearch}) async { fav.FavoriteChatUser favoriteChatUser = await ChatApiClient().favUser(userID: userID, targetUserID: targetUserID); if (favoriteChatUser.response != null) { for (ChatUser user in searchedChats!) { @@ -956,15 +954,16 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } } } - for (ChatUser user in favUsersList) { - if (user.id == targetUserID) { - user.userLocalDownlaodedImage = null; - user.isImageLoading = false; - user.isImageLoaded = false; + if (fromSearch) { + for (ChatUser user in favUsersList) { + if (user.id == targetUserID) { + user.userLocalDownlaodedImage = null; + user.isImageLoading = false; + user.isImageLoaded = false; + } } } notifyListeners(); - } Future unFavoriteUser({required int userID, required int targetUserID}) async { diff --git a/lib/ui/chat/chat_detailed_screen.dart b/lib/ui/chat/chat_detailed_screen.dart index dcbda22..595dc13 100644 --- a/lib/ui/chat/chat_detailed_screen.dart +++ b/lib/ui/chat/chat_detailed_screen.dart @@ -87,7 +87,6 @@ class _ChatDetailScreenState extends State { context, title: params!.chatUser!.userName.toString().replaceAll(".", " ").capitalizeFirstofEach, showHomeButton: false, - image: params!.chatUser!.image == null || params!.chatUser!.image.isEmpty ? null : params!.chatUser!.image, showTyping: true, chatUser: params!.chatUser, actions: [ diff --git a/lib/ui/chat/chat_home_screen.dart b/lib/ui/chat/chat_home_screen.dart index aed4048..aa47053 100644 --- a/lib/ui/chat/chat_home_screen.dart +++ b/lib/ui/chat/chat_home_screen.dart @@ -179,6 +179,7 @@ class _ChatHomeScreenState extends State { m.favoriteUser( userID: AppState().chatDetails!.response!.id!, targetUserID: m.searchedChats![index].id!, + fromSearch: false ); } else if (m.searchedChats![index].isFav == true) { m.unFavoriteUser( @@ -189,6 +190,7 @@ class _ChatHomeScreenState extends State { m.favoriteUser( userID: AppState().chatDetails!.response!.id!, targetUserID: m.searchedChats![index].id!, + fromSearch: false ); } }, diff --git a/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart b/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart index eada55f..d06bfdc 100644 --- a/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart +++ b/lib/widgets/bottom_sheets/search_employee_bottom_sheet.dart @@ -312,6 +312,7 @@ class _SearchEmployeeBottomSheetState extends State { .favoriteUser( userID: AppState().chatDetails!.response!.id!, targetUserID: provider.chatUsersList![index].id!, + fromSearch: true ) .then((value) { setState(() {}); @@ -330,6 +331,7 @@ class _SearchEmployeeBottomSheetState extends State { .favoriteUser( userID: AppState().chatDetails!.response!.id!, targetUserID: provider.chatUsersList![index].id!, + fromSearch: true ) .then((value) { setState(() {}); diff --git a/lib/widgets/chat_app_bar_widge.dart b/lib/widgets/chat_app_bar_widge.dart index a67ae7d..790840c 100644 --- a/lib/widgets/chat_app_bar_widge.dart +++ b/lib/widgets/chat_app_bar_widge.dart @@ -11,56 +11,75 @@ import 'package:mohem_flutter_app/widgets/circular_avatar.dart'; import 'package:provider/provider.dart'; AppBar ChatAppBarWidget(BuildContext context, - {required String title, - bool showHomeButton = true, - String? image, - ChatUser? chatUser, - bool showTyping = false, - List? actions, - void Function()? onHomeTapped, - void Function()? onBackTapped}) { + {required String title, bool showHomeButton = true, ChatUser? chatUser, bool showTyping = false, List? actions, void Function()? onHomeTapped, void Function()? onBackTapped}) { return AppBar( leadingWidth: 0, - title: Row( - children: [ - GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: Feedback.wrapForTap(() { - (onBackTapped == null ? Navigator.maybePop(context) : onBackTapped()); - }, context), - child: const Icon(Icons.arrow_back_ios, color: MyColors.darkIconColor), - ), - 4.width, - if (image != null) - CircularAvatar( - url: image, - height: 40, - width: 40, - isImageBase64: true, + title: Consumer(builder: (BuildContext cxt, ChatProviderModel data, Widget? child) { + return Row( + children: [ + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: Feedback.wrapForTap(() { + (onBackTapped == null ? Navigator.maybePop(context) : onBackTapped()); + }, context), + child: const Icon(Icons.arrow_back_ios, color: MyColors.darkIconColor), ), - if (image != null) 14.width, - SizedBox( - height: 40, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - title.toText20(color: MyColors.darkTextColor, isBold: true).expanded, - if (showTyping) - Consumer( - builder: (BuildContext cxt, ChatProviderModel data, Widget? child) { - if (chatUser!.isTyping!) { - return ("Typing ...").toText10(color: MyColors.textMixColor); - } else { - return const SizedBox(); - } - }, - ), - ], - ), - ) - ], - ), + 4.width, + if (chatUser != null) + Stack( + children: [ + if (chatUser.isImageLoading!) + const SizedBox( + height: 48, + width: 48, + ).toShimmer().circle(30), + if (!chatUser.isImageLoading! && chatUser.userLocalDownlaodedImage == null) + SvgPicture.asset( + "assets/images/user.svg", + height: 48, + width: 48, + ), + if (!chatUser.isImageLoading! && chatUser.userLocalDownlaodedImage != null) + Container( + width: 48.0, + height: 48.0, + decoration: BoxDecoration( + shape: BoxShape.circle, + image: DecorationImage( + fit: BoxFit.cover, + image: FileImage(chatUser.userLocalDownlaodedImage!), + ), + ), + ), + Positioned( + right: 5, + bottom: 1, + child: Container( + width: 10, + height: 10, + decoration: BoxDecoration( + color: chatUser.userStatus == 1 ? MyColors.green2DColor : Colors.red, + ), + ).circle(10), + ) + ], + ), + if (chatUser != null) 14.width, + SizedBox( + height: 40, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + title.toText20(color: MyColors.darkTextColor, isBold: true).expanded, + if (showTyping) + if (chatUser!.isTyping!) ("Typing ...").toText10(color: MyColors.textMixColor) else const SizedBox(), + ], + ), + ) + ], + ); + }), centerTitle: false, elevation: 0, backgroundColor: Colors.white,