From 83aabd05552aee12222c46317efcf259f447892b Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Mon, 14 Nov 2022 09:35:53 +0300 Subject: [PATCH] Chat Favorite Screen & Fixes --- lib/generated/codegen_loader.g.dart | 8 +- lib/ui/chat/chat_detailed_screen.dart | 4 +- lib/ui/chat/chat_home_screen.dart | 250 +++++++++++++------------ lib/ui/chat/favorite_users_screen.dart | 149 ++++++++------- 4 files changed, 209 insertions(+), 202 deletions(-) diff --git a/lib/generated/codegen_loader.g.dart b/lib/generated/codegen_loader.g.dart index e9dd08c..49dac5c 100644 --- a/lib/generated/codegen_loader.g.dart +++ b/lib/generated/codegen_loader.g.dart @@ -514,7 +514,9 @@ class CodegenLoader extends AssetLoader{ "verification": "تَحَقّق", "resend": "إعادة إرسال", "codeExpire": "انتهت صلاحية رمز التحقق", - "typeheretoreply": "اكتب هنا للرد" + "typeheretoreply": "اكتب هنا للرد", + "favorite": "مفضل", + "searchfromchat": "البحث من الدردشة" }; static const Map en_US = { "mohemm": "Mohemm", @@ -1016,7 +1018,9 @@ static const Map en_US = { "resend": "Resend", "codeExpire": "The verification code has been expired", "allQuestionsCorrect": "You have answered all questions correct", - "typeheretoreply": "Type here to reply" + "typeheretoreply": "Type here to reply", + "favorite": "Favorite", + "searchfromchat": "Search from chat" }; static const Map> mapLocales = {"ar_SA": ar_SA, "en_US": en_US}; } diff --git a/lib/ui/chat/chat_detailed_screen.dart b/lib/ui/chat/chat_detailed_screen.dart index 369bf3c..7dfb321 100644 --- a/lib/ui/chat/chat_detailed_screen.dart +++ b/lib/ui/chat/chat_detailed_screen.dart @@ -16,10 +16,12 @@ import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:swipe_to/swipe_to.dart'; class ChatDetailScreen extends StatelessWidget { - ChatDetailScreen({Key? key}) : super(key: key); dynamic userDetails; + late ChatProviderModel data; + ScrollController scrollController = ScrollController(); + final RefreshController _refreshController = RefreshController(initialRefresh: false); void getMoreChat() async { diff --git a/lib/ui/chat/chat_home_screen.dart b/lib/ui/chat/chat_home_screen.dart index 328354b..f10cc26 100644 --- a/lib/ui/chat/chat_home_screen.dart +++ b/lib/ui/chat/chat_home_screen.dart @@ -43,147 +43,149 @@ class _ChatHomeScreenState extends State { Widget build(BuildContext context) { return Scaffold( backgroundColor: MyColors.white, - body: Consumer(builder: (BuildContext context, ChatProviderModel m, Widget? child) { - return m.isLoading - ? ChatHomeShimmer() - : ListView( - shrinkWrap: true, - physics: const AlwaysScrollableScrollPhysics(), - children: [ - Padding( - padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 20), - child: TextField( - onChanged: (String val) { - m.filter(val); - }, - decoration: InputDecoration( - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(5), - borderSide: const BorderSide( - color: Color(0xFFE5E5E5), + body: Consumer( + builder: (BuildContext context, ChatProviderModel m, Widget? child) { + return m.isLoading + ? ChatHomeShimmer() + : ListView( + shrinkWrap: true, + physics: const AlwaysScrollableScrollPhysics(), + children: [ + Padding( + padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 20), + child: TextField( + onChanged: (String val) { + m.filter(val); + }, + decoration: InputDecoration( + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(5), + borderSide: const BorderSide( + color: Color(0xFFE5E5E5), + ), ), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(5), - borderSide: const BorderSide( - color: Color(0xFFE5E5E5), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(5), + borderSide: const BorderSide( + color: Color(0xFFE5E5E5), + ), ), - ), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(5), - borderSide: const BorderSide( - color: Color(0xFFE5E5E5), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(5), + borderSide: const BorderSide( + color: Color(0xFFE5E5E5), + ), ), + contentPadding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10), + hintText: LocaleKeys.searchfromchat.tr(), + hintStyle: const TextStyle(color: MyColors.lightTextColor, fontStyle: FontStyle.italic), + filled: true, + fillColor: const Color(0xFFF7F7F7), ), - contentPadding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10), - hintText: LocaleKeys.searchfromchat.tr(), - hintStyle: const TextStyle(color: MyColors.lightTextColor, fontStyle: FontStyle.italic), - filled: true, - fillColor: const Color(0xFFF7F7F7), ), ), - ), - if (m.searchedChats != null) - ListView.separated( - itemCount: m.searchedChats!.length, - padding: const EdgeInsets.only(bottom: 80), - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemBuilder: (BuildContext context, int index) { - return SizedBox( - height: 55, - child: ListTile( - leading: Stack( - children: [ - SvgPicture.asset( - "assets/images/user.svg", - height: 48, - width: 48, - ), - Positioned( - right: 5, - bottom: 1, - child: Container( - width: 10, - height: 10, - decoration: BoxDecoration( - color: m.searchedChats![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, - borderRadius: const BorderRadius.all( - Radius.circular(10), - ), - ), + if (m.searchedChats != null) + ListView.separated( + itemCount: m.searchedChats!.length, + padding: const EdgeInsets.only(bottom: 80), + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (BuildContext context, int index) { + return SizedBox( + height: 55, + child: ListTile( + leading: Stack( + children: [ + SvgPicture.asset( + "assets/images/user.svg", + height: 48, + width: 48, ), - ) - ], - ), - title: (m.searchedChats![index].userName ?? "").toText14(color: MyColors.darkTextColor), - // subtitle: (m.searchedChats![index].isTyping == true ? "Typing ..." : "").toText11(color: MyColors.normalTextColor), - trailing: SizedBox( - width: 60, - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.end, - mainAxisSize: MainAxisSize.max, - children: [ - if (m.searchedChats![index].unreadMessageCount! > 0) - Flexible( - child: Container( - padding: EdgeInsets.zero, - alignment: Alignment.centerRight, - width: 18, - height: 18, - decoration: const BoxDecoration( - color: MyColors.redColor, - borderRadius: BorderRadius.all( - Radius.circular(20), - ), + Positioned( + right: 5, + bottom: 1, + child: Container( + width: 10, + height: 10, + decoration: BoxDecoration( + color: m.searchedChats![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, + borderRadius: const BorderRadius.all( + Radius.circular(10), ), - child: (m.searchedChats![index].unreadMessageCount!.toString()) - .toText10( - color: MyColors.white, - ) - .center, ), ), - Flexible( - child: IconButton( - alignment: Alignment.centerRight, - padding: EdgeInsets.zero, - icon: Icon(m.searchedChats![index].isFav! ? Icons.star : Icons.star_border), - color: m.searchedChats![index].isFav! ? MyColors.yellowColor : MyColors.grey35Color, - onPressed: () { - if (m.searchedChats![index].isFav!) m.unFavoriteUser(userID: AppState().chatDetails!.response!.id!, targetUserID: m.searchedChats![index].id!); - if (!m.searchedChats![index].isFav!) m.favoriteUser(userID: AppState().chatDetails!.response!.id!, targetUserID: m.searchedChats![index].id!); - }, - ), ) ], ), + title: (m.searchedChats![index].userName ?? "").toText14(color: MyColors.darkTextColor), + // subtitle: (m.searchedChats![index].isTyping == true ? "Typing ..." : "").toText11(color: MyColors.normalTextColor), + trailing: SizedBox( + width: 60, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.end, + mainAxisSize: MainAxisSize.max, + children: [ + if (m.searchedChats![index].unreadMessageCount! > 0) + Flexible( + child: Container( + padding: EdgeInsets.zero, + alignment: Alignment.centerRight, + width: 18, + height: 18, + decoration: const BoxDecoration( + color: MyColors.redColor, + borderRadius: BorderRadius.all( + Radius.circular(20), + ), + ), + child: (m.searchedChats![index].unreadMessageCount!.toString()) + .toText10( + color: MyColors.white, + ) + .center, + ), + ), + Flexible( + child: IconButton( + alignment: Alignment.centerRight, + padding: EdgeInsets.zero, + icon: Icon(m.searchedChats![index].isFav! ? Icons.star : Icons.star_border), + color: m.searchedChats![index].isFav! ? MyColors.yellowColor : MyColors.grey35Color, + onPressed: () { + if (m.searchedChats![index].isFav!) m.unFavoriteUser(userID: AppState().chatDetails!.response!.id!, targetUserID: m.searchedChats![index].id!); + if (!m.searchedChats![index].isFav!) m.favoriteUser(userID: AppState().chatDetails!.response!.id!, targetUserID: m.searchedChats![index].id!); + }, + ), + ) + ], + ), + ), + minVerticalPadding: 0, + onTap: () { + Navigator.pushNamed( + context, + AppRoutes.chatDetailed, + arguments: {"targetUser": m.searchedChats![index]}, + ).then((value) { + m.clearSelections(); + }); + }, + onLongPress: () {}, ), - minVerticalPadding: 0, - onTap: () { - Navigator.pushNamed( - context, - AppRoutes.chatDetailed, - arguments: {"targetUser": m.searchedChats![index]}, - ).then((value) { - m.clearSelections(); - }); - }, - onLongPress: () {}, + ); + }, + separatorBuilder: (BuildContext context, int index) => const Padding( + padding: EdgeInsets.only(right: 10, left: 70), + child: Divider( + color: Color(0xFFE5E5E5), ), - ); - }, - separatorBuilder: (BuildContext context, int index) => const Padding( - padding: EdgeInsets.only(right: 10, left: 70), - child: Divider( - color: Color(0xFFE5E5E5), ), ), - ), - ], - ); - }), + ], + ); + }, + ), floatingActionButton: FloatingActionButton( child: Container( width: 60, diff --git a/lib/ui/chat/favorite_users_screen.dart b/lib/ui/chat/favorite_users_screen.dart index b84b827..2e3a3f2 100644 --- a/lib/ui/chat/favorite_users_screen.dart +++ b/lib/ui/chat/favorite_users_screen.dart @@ -12,91 +12,90 @@ import 'package:mohem_flutter_app/widgets/shimmer/dashboard_shimmer_widget.dart' import 'package:provider/provider.dart'; class ChatFavoriteUsersScreen extends StatelessWidget { - const ChatFavoriteUsersScreen({Key? key}) : super(key: key); - @override Widget build(BuildContext context) { - // TODO: implement build return Scaffold( backgroundColor: MyColors.white, - body: Consumer(builder: (BuildContext context, ChatProviderModel m, Widget? child) { - return m.isLoading - ? ChatHomeShimmer() - : ListView( - shrinkWrap: true, - physics: const AlwaysScrollableScrollPhysics(), - padding: const EdgeInsets.only(top: 20), - children: [ - if (m.favUsersList != null && m.favUsersList.isNotEmpty) - ListView.separated( - itemCount: m.favUsersList!.length, - padding: EdgeInsets.zero, - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemBuilder: (BuildContext context, int index) { - return SizedBox( - height: 55, - child: ListTile( - leading: Stack( - children: [ - SvgPicture.asset( - "assets/images/user.svg", - height: 48, - width: 48, - ), - Positioned( - right: 5, - bottom: 1, - child: Container( - width: 10, - height: 10, - decoration: BoxDecoration( - color: m.favUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, - borderRadius: const BorderRadius.all( - Radius.circular(10), - ), + body: Consumer( + builder: (BuildContext context, ChatProviderModel m, Widget? child) { + if (m.isLoading) { + return ChatHomeShimmer(); + } else { + return m.favUsersList != null && m.favUsersList.isNotEmpty + ? ListView.separated( + itemCount: m.favUsersList!.length, + padding: const EdgeInsets.only(top: 20), + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (BuildContext context, int index) { + return SizedBox( + height: 55, + child: ListTile( + leading: Stack( + children: [ + SvgPicture.asset( + "assets/images/user.svg", + height: 48, + width: 48, + ), + Positioned( + right: 5, + bottom: 1, + child: Container( + width: 10, + height: 10, + decoration: BoxDecoration( + color: m.favUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, + borderRadius: const BorderRadius.all( + Radius.circular(10), ), ), - ) - ], - ), - title: (m.favUsersList![index].userName ?? "").toText14(color: MyColors.darkTextColor), - // subtitle: (m.searchedChats![index].isTyping == true ? "Typing ..." : "").toText11(color: MyColors.normalTextColor), - trailing: IconButton( - alignment: Alignment.centerRight, - padding: EdgeInsets.zero, - icon: Icon(m.favUsersList![index].isFav! ? Icons.star : Icons.star_border), - color: m.favUsersList![index].isFav! ? MyColors.yellowColor : MyColors.grey35Color, - onPressed: () { - if (m.favUsersList![index].isFav!) m.unFavoriteUser(userID: AppState().chatDetails!.response!.id!, targetUserID: m.favUsersList![index].id!); - }, - ), - minVerticalPadding: 0, - onTap: () { - Navigator.pushNamed( - context, - AppRoutes.chatDetailed, - arguments: {"targetUser": m.favUsersList![index]}, - ).then((value) { - m.clearSelections(); - }); + ), + ) + ], + ), + title: (m.favUsersList![index].userName ?? "").toText14(color: MyColors.darkTextColor), + trailing: IconButton( + alignment: Alignment.centerRight, + padding: EdgeInsets.zero, + icon: Icon(m.favUsersList![index].isFav! ? Icons.star : Icons.star_border), + color: m.favUsersList![index].isFav! ? MyColors.yellowColor : MyColors.grey35Color, + onPressed: () { + if (m.favUsersList![index].isFav!) m.unFavoriteUser(userID: AppState().chatDetails!.response!.id!, targetUserID: m.favUsersList![index].id!); }, - onLongPress: () {}, ), - ); - }, - separatorBuilder: (BuildContext context, int index) => const Padding( - padding: EdgeInsets.only(right: 10, left: 70), - child: Divider( - color: Color(0xFFE5E5E5), + minVerticalPadding: 0, + onTap: () { + Navigator.pushNamed( + context, + AppRoutes.chatDetailed, + arguments: {"targetUser": m.favUsersList![index]}, + ).then( + (Object? value) { + m.clearSelections(); + }, + ); + }, + ), + ); + }, + separatorBuilder: (BuildContext context, int index) => const Padding( + padding: EdgeInsets.only(right: 10, left: 70), + child: Divider( + color: Color( + 0xFFE5E5E5, ), ), - ) - else - Utils.getNoDataWidget(context).expanded - ], - ); - }), + ), + ) + : Column( + children: [ + Utils.getNoDataWidget(context).expanded, + ], + ); + } + }, + ), ); } }