unread message list added.

design_3.0_loan_module
Sikander Saleem 18 hours ago
parent 4fdd04b106
commit c510c8e168

@ -54,6 +54,7 @@ import 'model/chat_attachment_model.dart';
import 'model/chat_participant_model.dart';
import 'model/get_search_user_chat_model.dart';
import 'model/get_single_user_chat_list_model.dart';
import 'model/unread_message_model.dart';
import 'model/user_chat_history_model.dart';
// import 'get_single_user_chat_list_model.dart';
@ -455,15 +456,21 @@ class ChatProvider with ChangeNotifier, DiagnosticableTreeMixin {
return result;
}
Future<List> getUnReadMessages(String employeeId) async {
Response response = await ApiClient().getJsonForResponse(
"${URLs.unreadMessages}?retrieveAll=true",
headers: {'x-api-key': URLs.chatApiKey, 'x-employee-number': employeeId},
);
if (response.statusCode == 200) {
List data = jsonDecode(response.body)["response"];
return data.map((elemet) => ChatAttachment.fromJson(elemet)).toList();
} else {
Future<List<UnReadMessage>> getUnReadMessages(String employeeId) async {
// employeeId = "FMEngineer";
try {
Response response = await ApiClient().getJsonForResponse(
"${URLs.unreadMessages}?retrieveAll=true",
headers: {'x-api-key': URLs.chatApiKey, 'x-employee-number': employeeId},
);
if (response.statusCode == 200) {
List data = jsonDecode(response.body);
return data.map((elemet) => UnReadMessage.fromJson(elemet)).toList();
} else {
return [];
}
} catch (error) {
return [];
}
}

@ -0,0 +1,48 @@
class UnReadMessage {
int? messageId;
int? conversationId;
String? senderEmployeeNumber;
String? senderUserName;
String? content;
String? createdAt;
String? moduleCode;
String? referenceId;
String? senderStatus;
UnReadMessage(
{this.messageId,
this.conversationId,
this.senderEmployeeNumber,
this.senderUserName,
this.content,
this.createdAt,
this.moduleCode,
this.referenceId,
this.senderStatus});
UnReadMessage.fromJson(Map<String, dynamic> json) {
messageId = json['messageId'];
conversationId = json['conversationId'];
senderEmployeeNumber = json['senderEmployeeNumber'];
senderUserName = json['senderUserName'];
content = json['content'];
createdAt = json['createdAt'];
moduleCode = json['moduleCode'];
referenceId = json['referenceId'];
senderStatus = json['senderStatus'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['messageId'] = this.messageId;
data['conversationId'] = this.conversationId;
data['senderEmployeeNumber'] = this.senderEmployeeNumber;
data['senderUserName'] = this.senderUserName;
data['content'] = this.content;
data['createdAt'] = this.createdAt;
data['moduleCode'] = this.moduleCode;
data['referenceId'] = this.referenceId;
data['senderStatus'] = this.senderStatus;
return data;
}
}

@ -1,12 +1,16 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/notification/firebase_notification_manger.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/modules/cx_module/chat/chat_provider.dart';
import 'package:test_sa/modules/cx_module/chat/model/unread_message_model.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
import '../../../widgets/loaders/no_data_found.dart';
import 'package:test_sa/extensions/string_extensions.dart';
import 'package:test_sa/views/widgets/loaders/no_data_found.dart';
class UnReadChatList extends StatelessWidget {
UnReadChatList({Key? key}) : super(key: key);
@ -15,139 +19,62 @@ class UnReadChatList extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: const DefaultAppBar(title: "Unread Messages"),
body: FutureBuilder<List>(
body: FutureBuilder<List<UnReadMessage>>(
future: Provider.of<ChatProvider>(context, listen: false).getUnReadMessages(context.userProvider.user!.employeeId ?? context.userProvider.user!.username!),
builder: (BuildContext context, AsyncSnapshot<List> snapshot) {
builder: (BuildContext context, AsyncSnapshot<List<UnReadMessage>> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) return const CircularProgressIndicator(color: AppColor.primary10).center;
if (snapshot.data == null) return const NoDataFound().center;
if (snapshot.data?.isEmpty ?? true) return const NoDataFound().center;
return SizedBox();
List<UnReadMessage> messages = snapshot.data!;
// List<LoanAttachmentModel> allAttachments = snapshot.data!.loanAttachments!;
//
// return Column(
// children: [
// ListView(
// padding: const EdgeInsets.all(16),
// children: [
// Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Row(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// StatusLabel(
// label: snapshot.data!.loanStatusName!,
// textColor: AppColor.getRequestStatusTextColorByName(context, snapshot.data!.loanStatusName!),
// backgroundColor: AppColor.getRequestStatusColorByName(context, snapshot.data!.loanStatusName!),
// ),
// 1.width.expanded,
// Text(
// snapshot.data!.createdDate?.toServiceRequestCardFormat ?? "-",
// textAlign: TextAlign.end,
// style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50),
// ),
// ],
// ),
// 12.height,
// ...requesterDetails(context, snapshot.data!),
// const Divider().defaultStyle(context),
// ...requestDetails(context, snapshot.data!),
// const Divider().defaultStyle(context),
// ...assetDetails(context, snapshot.data!),
// const Divider().defaultStyle(context),
// ...installationDetails(context, snapshot.data!),
// const Divider().defaultStyle(context),
// ...doctorDetails(context, snapshot.data!),
// const Divider().defaultStyle(context),
// ...vendorDetails(context, snapshot.data!),
// if (allAttachments.isNotEmpty) ...[
// const Divider().defaultStyle(context),
// Text(
// "Attachments".addTranslation,
// style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
// ),
// FilesList(images: allAttachments.map((e) => URLs.getFileUrl(e.attachmentName ?? '') ?? '').toList() ?? []),
// ],
// ],
// ).toShadowContainer(context, padding: 12),
// ],
// ).expanded,
// // @todo ask backend to add loanTypeValue, so we can show or hide the buttons
// if (snapshot.data?.loanTypeName == "Standard" &&
// context.userProvider.isEngineer &&
// (snapshot.data?.loanStatusValue == 4 || snapshot.data?.loanStatusValue == 5 || snapshot.data?.loanStatusValue == 8))
// FooterActionButton.footerContainer(
// context: context,
// child: AppFilledButton(
// onPressed: () async {
// if (snapshot.data?.loanStatusValue == 4) {
// String comment = "";
// context.showBottomSheet(
// Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisSize: MainAxisSize.min,
// children: [
// 'Estimated Date: ${snapshot.data?.installationEDD?.toAssetDetailsFormat ?? "-"}'.bodyText(context),
// 16.height,
// AppTextFormField(
// labelText: context.translation.comments,
// showSpeechToText: true,
// textInputType: TextInputType.multiline,
// labelStyle: AppTextStyles.textFieldLabelStyle,
// showWithoutDecoration: true,
// backgroundColor: context.isDarkNotListen ? AppColor.neutral20 : AppColor.neutral100,
// alignLabelWithHint: true,
// onChange: (text) {
// comment = text;
// },
// ),
// 16.height,
// AppFilledButton(
// onPressed: () async {
// Utils.showLoading(context);
// LoanProvider loanProvider = Provider.of<LoanProvider>(context, listen: false);
// bool isSuccess = await loanProvider.loanWorkflowAction({
// "userId": context.userProvider.user!.userID,
// "isFromMobile": true,
// "commentsFromMobile": comment,
// 'loanId': snapshot.data?.id,
// 'loanStatusId': snapshot.data?.loanStatusValue,
// });
// Utils.hideLoading(context);
// if (isSuccess) {
// Navigator.pop(context, true);
// setState(() {});
// }
// },
// label: "Delivered"),
// ],
// ),
// title: "EDD & Comments",
// showCancelButton: true);
// return;
// }
// if (snapshot.data?.loanStatusValue == 5) {
// bool isSuccess = await Navigator.push(context, MaterialPageRoute(builder: (context) => InstallationFormView(loanData: snapshot.data))) ?? false;
// if (isSuccess) {
// setState(() {});
// }
// return;
// }
// bool isSuccess = await Navigator.push(context, MaterialPageRoute(builder: (context) => PullOutDetailsPage(loanData: snapshot.data))) ?? false;
// if (isSuccess) {
// setState(() {});
// }
// },
// label: snapshot.data?.loanStatusValue == 4
// ? "Delivered"
// : snapshot.data?.loanStatusValue == 5
// ? 'Installation Report'
// : 'PullOut Report',
// ),
// )
// ],
// );
return SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.all(0),
itemCount: messages.length,
separatorBuilder: (context, itemIndex) => const Divider().defaultStyle(context),
itemBuilder: (context, index) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
messages[index].senderUserName ?? "",
style: AppTextStyles.bodyText.copyWith(
color: context.isDark ? AppColor.neutral30 : AppColor.neutral50,
),
).expanded,
8.width,
Text(
messages[index].createdAt?.toServiceRequestCardFormat ?? "",
textAlign: TextAlign.right,
style: AppTextStyles.tinyFont.copyWith(
color: context.isDark ? AppColor.neutral20 : AppColor.neutral50,
),
),
],
),
Text(
messages[index].content ?? "",
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral10 : const Color(0xFF757575)),
),
],
).onPress(() {
FirebaseNotificationManger.handleMessage(context, {
"transactionType": "17",
"requestType": "chat",
"moduleId": messages[index].moduleCode,
"requestNumber": messages[index].conversationId,
});
});
},
).toShadowContainer(context),
);
}));
}
}

Loading…
Cancel
Save