App Bar online / Offline & Fixes

merge-requests/127/head
Aamir Muhammad 3 years ago
parent d24fa6b61b
commit 5028a3b860

@ -175,9 +175,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
if (response.statusCode == 204) { if (response.statusCode == 204) {
if (isNewChat) { if (isNewChat) {
userChatHistory = []; userChatHistory = [];
} else if (loadMore) { } else if (loadMore) {}
}
} else { } else {
if (loadMore) { if (loadMore) {
List<SingleUserChatModel> temp = getSingleUserChatModel(response.body).reversed.toList(); List<SingleUserChatModel> temp = getSingleUserChatModel(response.body).reversed.toList();
@ -933,7 +931,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
return f.format(data); return f.format(data);
} }
Future<void> favoriteUser({required int userID, required int targetUserID}) async { Future<void> favoriteUser({required int userID, required int targetUserID, required bool fromSearch}) async {
fav.FavoriteChatUser favoriteChatUser = await ChatApiClient().favUser(userID: userID, targetUserID: targetUserID); fav.FavoriteChatUser favoriteChatUser = await ChatApiClient().favUser(userID: userID, targetUserID: targetUserID);
if (favoriteChatUser.response != null) { if (favoriteChatUser.response != null) {
for (ChatUser user in searchedChats!) { for (ChatUser user in searchedChats!) {
@ -956,6 +954,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
} }
} }
if (fromSearch) {
for (ChatUser user in favUsersList) { for (ChatUser user in favUsersList) {
if (user.id == targetUserID) { if (user.id == targetUserID) {
user.userLocalDownlaodedImage = null; user.userLocalDownlaodedImage = null;
@ -963,8 +962,8 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
user.isImageLoaded = false; user.isImageLoaded = false;
} }
} }
}
notifyListeners(); notifyListeners();
} }
Future<void> unFavoriteUser({required int userID, required int targetUserID}) async { Future<void> unFavoriteUser({required int userID, required int targetUserID}) async {

@ -87,7 +87,6 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
context, context,
title: params!.chatUser!.userName.toString().replaceAll(".", " ").capitalizeFirstofEach, title: params!.chatUser!.userName.toString().replaceAll(".", " ").capitalizeFirstofEach,
showHomeButton: false, showHomeButton: false,
image: params!.chatUser!.image == null || params!.chatUser!.image.isEmpty ? null : params!.chatUser!.image,
showTyping: true, showTyping: true,
chatUser: params!.chatUser, chatUser: params!.chatUser,
actions: [ actions: [

@ -179,6 +179,7 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
m.favoriteUser( m.favoriteUser(
userID: AppState().chatDetails!.response!.id!, userID: AppState().chatDetails!.response!.id!,
targetUserID: m.searchedChats![index].id!, targetUserID: m.searchedChats![index].id!,
fromSearch: false
); );
} else if (m.searchedChats![index].isFav == true) { } else if (m.searchedChats![index].isFav == true) {
m.unFavoriteUser( m.unFavoriteUser(
@ -189,6 +190,7 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
m.favoriteUser( m.favoriteUser(
userID: AppState().chatDetails!.response!.id!, userID: AppState().chatDetails!.response!.id!,
targetUserID: m.searchedChats![index].id!, targetUserID: m.searchedChats![index].id!,
fromSearch: false
); );
} }
}, },

@ -312,6 +312,7 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
.favoriteUser( .favoriteUser(
userID: AppState().chatDetails!.response!.id!, userID: AppState().chatDetails!.response!.id!,
targetUserID: provider.chatUsersList![index].id!, targetUserID: provider.chatUsersList![index].id!,
fromSearch: true
) )
.then((value) { .then((value) {
setState(() {}); setState(() {});
@ -330,6 +331,7 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
.favoriteUser( .favoriteUser(
userID: AppState().chatDetails!.response!.id!, userID: AppState().chatDetails!.response!.id!,
targetUserID: provider.chatUsersList![index].id!, targetUserID: provider.chatUsersList![index].id!,
fromSearch: true
) )
.then((value) { .then((value) {
setState(() {}); setState(() {});

@ -11,17 +11,11 @@ import 'package:mohem_flutter_app/widgets/circular_avatar.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
AppBar ChatAppBarWidget(BuildContext context, AppBar ChatAppBarWidget(BuildContext context,
{required String title, {required String title, bool showHomeButton = true, ChatUser? chatUser, bool showTyping = false, List<Widget>? actions, void Function()? onHomeTapped, void Function()? onBackTapped}) {
bool showHomeButton = true,
String? image,
ChatUser? chatUser,
bool showTyping = false,
List<Widget>? actions,
void Function()? onHomeTapped,
void Function()? onBackTapped}) {
return AppBar( return AppBar(
leadingWidth: 0, leadingWidth: 0,
title: Row( title: Consumer<ChatProviderModel>(builder: (BuildContext cxt, ChatProviderModel data, Widget? child) {
return Row(
children: [ children: [
GestureDetector( GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
@ -31,14 +25,46 @@ AppBar ChatAppBarWidget(BuildContext context,
child: const Icon(Icons.arrow_back_ios, color: MyColors.darkIconColor), child: const Icon(Icons.arrow_back_ios, color: MyColors.darkIconColor),
), ),
4.width, 4.width,
if (image != null) if (chatUser != null)
CircularAvatar( Stack(
url: image, children: <Widget>[
height: 40, if (chatUser.isImageLoading!)
width: 40, const SizedBox(
isImageBase64: true, 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 (image != null) 14.width, if (chatUser != null) 14.width,
SizedBox( SizedBox(
height: 40, height: 40,
child: Column( child: Column(
@ -47,20 +73,13 @@ AppBar ChatAppBarWidget(BuildContext context,
children: [ children: [
title.toText20(color: MyColors.darkTextColor, isBold: true).expanded, title.toText20(color: MyColors.darkTextColor, isBold: true).expanded,
if (showTyping) if (showTyping)
Consumer<ChatProviderModel>( if (chatUser!.isTyping!) ("Typing ...").toText10(color: MyColors.textMixColor) else const SizedBox(),
builder: (BuildContext cxt, ChatProviderModel data, Widget? child) {
if (chatUser!.isTyping!) {
return ("Typing ...").toText10(color: MyColors.textMixColor);
} else {
return const SizedBox();
}
},
),
], ],
), ),
) )
], ],
), );
}),
centerTitle: false, centerTitle: false,
elevation: 0, elevation: 0,
backgroundColor: Colors.white, backgroundColor: Colors.white,

Loading…
Cancel
Save