Merge branch 'design_3.0_loan_module' into design_3.0_demo_module
# Conflicts: # lib/controllers/api_routes/urls.dart # lib/models/generic_attachment_model.dart # lib/modules/loan_module/pages/loan_equipment_detail_page.dartdesign_3.0_demo_module
commit
2e3736cdc9
@ -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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,223 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:test_sa/extensions/context_extension.dart';
|
||||
import 'package:test_sa/extensions/int_extensions.dart';
|
||||
import 'package:test_sa/extensions/string_extensions.dart';
|
||||
import 'package:test_sa/extensions/text_extensions.dart';
|
||||
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||
import 'package:test_sa/helper/utils.dart';
|
||||
import 'package:test_sa/models/generic_attachment_model.dart';
|
||||
import 'package:test_sa/models/timer_model.dart';
|
||||
import 'package:test_sa/modules/cm_module/cm_request_utils.dart';
|
||||
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart';
|
||||
import 'package:test_sa/modules/loan_module/models/loan_form_model.dart';
|
||||
import 'package:test_sa/modules/loan_module/models/loan_installation_pullout_form_model.dart';
|
||||
import 'package:test_sa/modules/loan_module/models/loan_request_model.dart';
|
||||
import 'package:test_sa/modules/loan_module/provider/loan_provider.dart';
|
||||
import 'package:test_sa/new_views/app_style/app_color.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
||||
import 'package:test_sa/views/widgets/date_and_time/date_picker.dart';
|
||||
import 'package:test_sa/views/widgets/e_signature/e_signature.dart';
|
||||
import 'package:test_sa/views/widgets/images/multi_image_picker.dart';
|
||||
import 'package:test_sa/views/widgets/timer/app_timer.dart';
|
||||
|
||||
class InstallationFormView extends StatefulWidget {
|
||||
LoanRequestModel? loanData;
|
||||
bool isInstallation;
|
||||
|
||||
InstallationFormView({Key? key, this.loanData, this.isInstallation = true}) : super(key: key);
|
||||
|
||||
@override
|
||||
_InstallationFormViewState createState() {
|
||||
return _InstallationFormViewState();
|
||||
}
|
||||
}
|
||||
|
||||
class _InstallationFormViewState extends State<InstallationFormView> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
List<GenericAttachmentModel> _attachments = [];
|
||||
|
||||
final LoanInstallationPullOutFormModel _formData = LoanInstallationPullOutFormModel();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_formData.loanId = widget.loanData?.id;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void updateTimer({TimerModel? timer}) {
|
||||
if (timer?.startAt != null && timer?.endAt != null) {
|
||||
final start = timer!.startAt!;
|
||||
final end = timer.endAt!;
|
||||
final difference = end.difference(start);
|
||||
final totalHours = difference.inSeconds / 3600.0;
|
||||
_formData.startTime = start;
|
||||
_formData.endTime = end;
|
||||
_formData.totalHours = totalHours;
|
||||
}
|
||||
|
||||
if (timer == null) {
|
||||
_formData.startTime = null;
|
||||
_formData.endTime = null;
|
||||
_formData.totalHours = null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: DefaultAppBar(title: 'Installation Report'.addTranslation),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (widget.isInstallation) ...[
|
||||
AppTextFormField(
|
||||
initialValue: "",
|
||||
labelText: "Updates SN",
|
||||
validator: (value) {
|
||||
if ((value ?? "").isEmpty) return "Mandatory";
|
||||
return null;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
showShadow: false,
|
||||
textInputType: TextInputType.text,
|
||||
textInputAction: TextInputAction.next,
|
||||
onChange: (value) {
|
||||
_formData.snNo = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
],
|
||||
ADatePicker(
|
||||
label: widget.isInstallation ? "Installation Date".addTranslation : "Validation Date".addTranslation,
|
||||
hideShadow: true,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
to: DateTime.now().add(const Duration(days: 365)),
|
||||
formatDateWithTime: true,
|
||||
date: _formData.date,
|
||||
onDatePicker: (DateTime date) async {
|
||||
final time = await showTimePicker(context: context, initialTime: TimeOfDay.now());
|
||||
if (time == null) return;
|
||||
setState(() {
|
||||
_formData.date = DateTime(date.year, date.month, date.day, time.hour, time.minute);
|
||||
});
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTimer(
|
||||
label: context.translation.workingHours,
|
||||
timer: _formData.timerModel,
|
||||
// pickerFromDate: DateTime.tryParse(widget.createdDate ?? ''),
|
||||
pickerFromDate: DateTime(DateTime.now().year, DateTime.now().month, 1),
|
||||
pickerTimer: _formData.timerModel,
|
||||
showTimer: false,
|
||||
onPick: (timer) {
|
||||
updateTimer(timer: timer);
|
||||
},
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.fieldBgColor(context),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
timerProgress: (isRunning) {},
|
||||
onChange: (timer) async {
|
||||
updateTimer(timer: timer);
|
||||
return true;
|
||||
},
|
||||
),
|
||||
ESignature(
|
||||
title: 'End-user signature'.addTranslation,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
showShadow: false,
|
||||
oldSignature: '',
|
||||
newSignature: _formData.signature,
|
||||
onChange: (Uint8List signature) {
|
||||
if (signature.isEmpty) return;
|
||||
setState(() {
|
||||
_formData.signature = signature;
|
||||
});
|
||||
},
|
||||
),
|
||||
24.height,
|
||||
"Attachments".bodyText(context).custom(color: AppColor.black10),
|
||||
8.height,
|
||||
AttachmentPicker(
|
||||
label: context.translation.attachments,
|
||||
attachment: _attachments,
|
||||
buttonColor: AppColor.primary10,
|
||||
onlyImages: false,
|
||||
showAsListView: true,
|
||||
buttonIcon: 'attachment_icon'.toSvgAsset(color: AppColor.primary10),
|
||||
onChange: (attachments) {
|
||||
_attachments = attachments;
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
],
|
||||
).toShadowContainer(context, borderRadius: 20),
|
||||
).expanded,
|
||||
FooterActionButton.footerContainer(
|
||||
context: context,
|
||||
child: AppFilledButton(
|
||||
buttonColor: AppColor.primary10,
|
||||
label: context.translation.submitRequest,
|
||||
onPressed: _submitForm,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _submitForm() async {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
if (_formData.date == null) {
|
||||
"Please select installation date".showToast;
|
||||
return;
|
||||
}
|
||||
if (_formData.startTime == null || _formData.endTime == null) {
|
||||
"Please select start and end time".showToast;
|
||||
return;
|
||||
}
|
||||
if (_formData.signature == null || _formData.signature!.isEmpty) {
|
||||
"Signature is required".showToast;
|
||||
return;
|
||||
}
|
||||
|
||||
_formData.loanAttachment = [];
|
||||
|
||||
for (var item in _attachments) {
|
||||
String fileName = CMRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? '';
|
||||
_formData.loanAttachment!.add(LoanAttachments(id: 0, attachmentName: fileName, loanId: widget.loanData?.id));
|
||||
}
|
||||
Utils.showLoading(context);
|
||||
_formData.loanStatusId = widget.loanData?.loanStatusValue;
|
||||
_formData.userId = context.userProvider.user?.userID;
|
||||
LoanProvider incidentProvider = Provider.of<LoanProvider>(context, listen: false);
|
||||
bool isSuccess = await incidentProvider.loanWorkflowAction(_formData.toInstallationJson());
|
||||
Utils.hideLoading(context);
|
||||
if (isSuccess) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
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 '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);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: const DefaultAppBar(title: "Unread Messages"),
|
||||
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<UnReadMessage>> snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) return const CircularProgressIndicator(color: AppColor.primary10).center;
|
||||
if (snapshot.data?.isEmpty ?? true) return const NoDataFound().center;
|
||||
|
||||
List<UnReadMessage> messages = snapshot.data!;
|
||||
|
||||
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].referenceId,
|
||||
});
|
||||
});
|
||||
},
|
||||
).toShadowContainer(context),
|
||||
);
|
||||
}));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue