merge-requests/126/head
Aamir Muhammad 3 years ago
parent ec2bdedeef
commit 3871d3f1e3

@ -46,15 +46,15 @@ class ChatApiClient {
return userLoginResponse; return userLoginResponse;
} }
Future<List<ChatUser>?> getChatMemberFromSearch(String sName, int cUserId) async { Future<ChatUserModel> getChatMemberFromSearch(String searchParam, int cUserId, int pageNo) async {
Response response = await ApiClient().getJsonForResponse( ChatUserModel chatUserModel;
"${ApiConsts.chatLoginTokenUrl}getUserWithStatusAndFavAsync/$sName/$cUserId", Response response = await ApiClient().postJsonForResponse("${ApiConsts.chatLoginTokenUrl}getUserWithStatusAndFavAsync", {"employeeNumber": cUserId, "userName": searchParam, "pageNumber": pageNo},
token: AppState().chatDetails!.response!.token, token: AppState().chatDetails!.response!.token);
);
if (!kReleaseMode) { if (!kReleaseMode) {
logger.i("res: " + response.body); logger.i("res: " + response.body);
} }
return List<ChatUser>.from(json.decode(response.body).map((x) => ChatUser.fromJson(x))); chatUserModel = chatUserModelFromJson(response.body);
return chatUserModel;
} }
//Get User Recent Chats //Get User Recent Chats

@ -1,5 +1,11 @@
import 'dart:convert';
import 'dart:io'; import 'dart:io';
ChatUserModel chatUserModelFromJson(String str) => ChatUserModel.fromJson(json.decode(str));
String chatUserModelToJson(ChatUserModel data) => json.encode(data.toJson());
class ChatUserModel { class ChatUserModel {
ChatUserModel({ ChatUserModel({
this.response, this.response,
@ -7,16 +13,40 @@ class ChatUserModel {
}); });
List<ChatUser>? response; List<ChatUser>? response;
dynamic errorResponses; List<ErrorResponse>? errorResponses;
factory ChatUserModel.fromJson(Map<String, dynamic> json) => ChatUserModel( factory ChatUserModel.fromJson(Map<String, dynamic> json) => ChatUserModel(
response: json["response"] == null ? null : List<ChatUser>.from(json["response"].map((x) => ChatUser.fromJson(x))), response: json["response"] == null ? null : List<ChatUser>.from(json["response"].map((x) => ChatUser.fromJson(x))),
errorResponses: json["errorResponses"], errorResponses: json["errorResponses"] == null ? null : List<ErrorResponse>.from(json["errorResponses"].map((x) => ErrorResponse.fromJson(x))),
); );
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
"response": response == null ? null : List<dynamic>.from(response!.map((x) => x.toJson())), "response": response == null ? null : List<dynamic>.from(response!.map((x) => x.toJson())),
"errorResponses": errorResponses, "errorResponses": errorResponses == null ? null : List<dynamic>.from(errorResponses!.map((x) => x.toJson())),
};
}
class ErrorResponse {
ErrorResponse({
this.fieldName,
this.message,
});
dynamic? fieldName;
String? message;
factory ErrorResponse.fromRawJson(String str) => ErrorResponse.fromJson(json.decode(str));
String toRawJson() => json.encode(toJson());
factory ErrorResponse.fromJson(Map<String, dynamic> json) => ErrorResponse(
fieldName: json["fieldName"],
message: json["message"] == null ? null : json["message"],
);
Map<String, dynamic> toJson() => {
"fieldName": fieldName,
"message": message == null ? null : message,
}; };
} }
@ -34,6 +64,8 @@ class ChatUser {
this.isPin, this.isPin,
this.isFav, this.isFav,
this.isAdmin, this.isAdmin,
this.rKey,
this.totalCount,
this.isTyping, this.isTyping,
this.isImageLoaded, this.isImageLoaded,
this.isImageLoading, this.isImageLoading,
@ -44,7 +76,7 @@ class ChatUser {
String? userName; String? userName;
String? email; String? email;
dynamic? phone; dynamic? phone;
dynamic? title; String? title;
int? userStatus; int? userStatus;
dynamic? image; dynamic? image;
int? unreadMessageCount; int? unreadMessageCount;
@ -52,17 +84,23 @@ class ChatUser {
bool? isPin; bool? isPin;
bool? isFav; bool? isFav;
bool? isAdmin; bool? isAdmin;
dynamic? rKey;
int? totalCount;
bool? isTyping; bool? isTyping;
bool? isImageLoaded; bool? isImageLoaded;
bool? isImageLoading; bool? isImageLoading;
File? userLocalDownlaodedImage; File? userLocalDownlaodedImage;
factory ChatUser.fromRawJson(String str) => ChatUser.fromJson(json.decode(str));
String toRawJson() => json.encode(toJson());
factory ChatUser.fromJson(Map<String, dynamic> json) => ChatUser( factory ChatUser.fromJson(Map<String, dynamic> json) => ChatUser(
id: json["id"] == null ? null : json["id"], id: json["id"] == null ? null : json["id"],
userName: json["userName"] == null ? null : json["userName"], userName: json["userName"] == null ? null : json["userName"],
email: json["email"] == null ? null : json["email"], email: json["email"] == null ? null : json["email"],
phone: json["phone"], phone: json["phone"],
title: json["title"], title: json["title"] == null ? null : json["title"],
userStatus: json["userStatus"] == null ? null : json["userStatus"], userStatus: json["userStatus"] == null ? null : json["userStatus"],
image: json["image"], image: json["image"],
unreadMessageCount: json["unreadMessageCount"] == null ? null : json["unreadMessageCount"], unreadMessageCount: json["unreadMessageCount"] == null ? null : json["unreadMessageCount"],
@ -70,6 +108,8 @@ class ChatUser {
isPin: json["isPin"] == null ? null : json["isPin"], isPin: json["isPin"] == null ? null : json["isPin"],
isFav: json["isFav"] == null ? null : json["isFav"], isFav: json["isFav"] == null ? null : json["isFav"],
isAdmin: json["isAdmin"] == null ? null : json["isAdmin"], isAdmin: json["isAdmin"] == null ? null : json["isAdmin"],
rKey: json["rKey"],
totalCount: json["totalCount"] == null ? null : json["totalCount"],
isTyping: false, isTyping: false,
isImageLoaded: false, isImageLoaded: false,
isImageLoading: true, isImageLoading: true,
@ -80,7 +120,7 @@ class ChatUser {
"userName": userName == null ? null : userName, "userName": userName == null ? null : userName,
"email": email == null ? null : email, "email": email == null ? null : email,
"phone": phone, "phone": phone,
"title": title, "title": title == null ? null : title,
"userStatus": userStatus == null ? null : userStatus, "userStatus": userStatus == null ? null : userStatus,
"image": image, "image": image,
"unreadMessageCount": unreadMessageCount == null ? null : unreadMessageCount, "unreadMessageCount": unreadMessageCount == null ? null : unreadMessageCount,
@ -88,5 +128,7 @@ class ChatUser {
"isPin": isPin == null ? null : isPin, "isPin": isPin == null ? null : isPin,
"isFav": isFav == null ? null : isFav, "isFav": isFav == null ? null : isFav,
"isAdmin": isAdmin == null ? null : isAdmin, "isAdmin": isAdmin == null ? null : isAdmin,
"rKey": rKey,
"totalCount": totalCount == null ? null : totalCount,
}; };
} }

@ -82,7 +82,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
Future<void> buildHubConnection() async { Future<void> buildHubConnection() async {
chatHubConnection = await getHubConnection(); chatHubConnection = await getHubConnection();
await chatHubConnection.start(); await chatHubConnection.start();
if (kDebugMode) { if (kDebugMode) {
@ -173,7 +172,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
if (isNewChat) { if (isNewChat) {
userChatHistory = []; userChatHistory = [];
} else if (loadMore) { } else if (loadMore) {
Utils.showToast("No More Data To Load");
} }
} else { } else {
if (loadMore) { if (loadMore) {
@ -330,7 +329,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
user.userStatus = items.first["userStatus"]; user.userStatus = items.first["userStatus"];
} }
} }
if (teamMembersList != null) {
if (teamMembersList.isNotEmpty) {
for (ChatUser user in teamMembersList!) {
if (user.id == items.first["id"]) {
user.userStatus = items.first["userStatus"];
}
}
}
}
notifyListeners(); notifyListeners();
} }

@ -238,6 +238,7 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
), ),
), ),
onPressed: () async { onPressed: () async {
print(AppState().chatDetails!.response!.token);
showMyBottomSheet( showMyBottomSheet(
context, context,
callBackFunc: () {}, callBackFunc: () {},

@ -24,6 +24,7 @@ import 'package:mohem_flutter_app/ui/chat/chat_detailed_screen.dart';
import 'package:mohem_flutter_app/widgets/button/default_button.dart'; import 'package:mohem_flutter_app/widgets/button/default_button.dart';
import 'package:mohem_flutter_app/widgets/circular_avatar.dart'; import 'package:mohem_flutter_app/widgets/circular_avatar.dart';
import 'package:mohem_flutter_app/widgets/dynamic_forms/dynamic_textfield_widget.dart'; import 'package:mohem_flutter_app/widgets/dynamic_forms/dynamic_textfield_widget.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
class SearchEmployeeBottomSheet extends StatefulWidget { class SearchEmployeeBottomSheet extends StatefulWidget {
int? notificationID; int? notificationID;
@ -47,6 +48,8 @@ class SearchEmployeeBottomSheet extends StatefulWidget {
class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> { class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
TextEditingController username = TextEditingController(); TextEditingController username = TextEditingController();
ScrollController sc = ScrollController();
String searchText = ""; String searchText = "";
List<String>? optionsList = [ List<String>? optionsList = [
@ -62,6 +65,7 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
// Chat Items // Chat Items
List<ChatUser>? chatUsersList = []; List<ChatUser>? chatUsersList = [];
int pageNo = 1;
int _selectedSearchIndex = 0; int _selectedSearchIndex = 0;
@ -88,12 +92,16 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
} }
void fetchChatUser({bool isNeedLoading = true}) async { void fetchChatUser({bool isNeedLoading = true}) async {
if (pageNo == 1)
chatUsersList = [];
try { try {
Utils.showLoading(context); Utils.showLoading(context);
chatUsersList = await ChatApiClient().getChatMemberFromSearch( await ChatApiClient().getChatMemberFromSearch(searchText, AppState().chatDetails!.response!.id!, pageNo).then((ChatUserModel value) {
searchText, print(value.response!.length);
int.parse(AppState().chatDetails!.response!.id.toString()), if (value.response != null) {
); chatUsersList = value.response;
}
});
chatUsersList!.removeWhere((ChatUser element) => element.id == AppState().chatDetails!.response!.id); chatUsersList!.removeWhere((ChatUser element) => element.id == AppState().chatDetails!.response!.id);
Utils.hideLoading(context); Utils.hideLoading(context);
setState(() {}); setState(() {});
@ -107,11 +115,41 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
return null; return null;
} }
void loadMoreChatUsers() async {
try {
await ChatApiClient().getChatMemberFromSearch(searchText, AppState().chatDetails!.response!.id!, pageNo).then((ChatUserModel value) {
if (value.response != null) {
chatUsersList!.addAll(value.response!);
}
});
chatUsersList!.removeWhere((ChatUser element) => element.id == AppState().chatDetails!.response!.id);
} catch (e) {
Utils.hideLoading(context);
Utils.handleException(e, context, null);
}
}
void scrollListener() async {
if (sc.position.pixels ==
sc.position.maxScrollExtent) {
pageNo++;
setState(() {});
}
@override
void initState() {
super.initState();
sc.addListener(scrollListener);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SizedBox( return SizedBox(
width: double.infinity, width: double.infinity,
height: MediaQuery.of(context).size.height - 100, height: MediaQuery
.of(context)
.size
.height - 100,
child: Column( child: Column(
children: [ children: [
Column( Column(
@ -153,7 +191,9 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
), ),
if (replacementList != null) if (replacementList != null)
replacementList!.isEmpty replacementList!.isEmpty
? Utils.getNoDataWidget(context).expanded ? Utils
.getNoDataWidget(context)
.expanded
: ListView( : ListView(
physics: const BouncingScrollPhysics(), physics: const BouncingScrollPhysics(),
padding: EdgeInsets.only(top: 21, bottom: 8), padding: EdgeInsets.only(top: 21, bottom: 8),
@ -165,7 +205,8 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true, shrinkWrap: true,
itemBuilder: (cxt, index) => employeeItemView(favouriteUserList![index]), itemBuilder: (cxt, index) => employeeItemView(favouriteUserList![index]),
separatorBuilder: (cxt, index) => Container( separatorBuilder: (cxt, index) =>
Container(
height: 1, height: 1,
color: MyColors.borderE3Color, color: MyColors.borderE3Color,
), ),
@ -179,7 +220,8 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true, shrinkWrap: true,
itemBuilder: (cxt, index) => employeeItemView(nonFavouriteUserList![index]), itemBuilder: (cxt, index) => employeeItemView(nonFavouriteUserList![index]),
separatorBuilder: (cxt, index) => Container( separatorBuilder: (cxt, index) =>
Container(
height: 1, height: 1,
color: MyColors.borderE3Color, color: MyColors.borderE3Color,
), ),
@ -196,14 +238,10 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
Utils.getNoDataWidget(context), Utils.getNoDataWidget(context),
], ],
) )
: ListView( : ListView
physics: const BouncingScrollPhysics(), .separated(
padding: const EdgeInsets.only( physics: const AlwaysScrollableScrollPhysics(),
top: 15, controller: sc,
),
children: <Widget>[
ListView.separated(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true, shrinkWrap: true,
itemBuilder: (BuildContext cxt, int index) { itemBuilder: (BuildContext cxt, int index) {
return SizedBox( return SizedBox(
@ -245,19 +283,20 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
), ),
); );
}, },
separatorBuilder: (BuildContext context, int index) => const Padding( separatorBuilder: (BuildContext context, int index) =>
const Padding(
padding: EdgeInsets.only(right: 10, left: 70, bottom: 0, top: 0), padding: EdgeInsets.only(right: 10, left: 70, bottom: 0, top: 0),
child: Divider( child: Divider(
color: Color(0xFFE5E5E5), color: Color(0xFFE5E5E5),
), ),
), ),
itemCount: chatUsersList?.length ?? 0, itemCount: chatUsersList?.length ?? 0,
), )
12.height, .expanded,
],
).expanded,
], ],
).paddingOnly(left: 21, right: 21, bottom: 0, top: 21).expanded, )
.paddingOnly(left: 21, right: 21, bottom: 0, top: 21)
.expanded,
Container(width: double.infinity, height: 1, color: MyColors.lightGreyEFColor), Container(width: double.infinity, height: 1, color: MyColors.lightGreyEFColor),
DefaultButton( DefaultButton(
LocaleKeys.cancel.tr(), LocaleKeys.cancel.tr(),

@ -273,7 +273,7 @@ class ChatHomeShimmer extends StatelessWidget {
children: <Widget>[ children: <Widget>[
Container( Container(
width: double.infinity, width: double.infinity,
height: 8.0, height: 20.0,
color: Colors.white, color: Colors.white,
), ),
const Padding( const Padding(
@ -281,7 +281,7 @@ class ChatHomeShimmer extends StatelessWidget {
), ),
Container( Container(
width: double.infinity, width: double.infinity,
height: 8.0, height: 15.0,
color: Colors.white, color: Colors.white,
), ),
const Padding( const Padding(
@ -289,7 +289,7 @@ class ChatHomeShimmer extends StatelessWidget {
), ),
Container( Container(
width: 40.0, width: 40.0,
height: 8.0, height: 10.0,
color: Colors.white, color: Colors.white,
), ),
], ],

Loading…
Cancel
Save