fixed date pickering issue
This commit is contained in:
parent
502bb1e2d9
commit
8d688f2575
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
import 'package:marco/controller/finance/add_payment_request_controller.dart';
|
import 'package:marco/controller/finance/add_payment_request_controller.dart';
|
||||||
import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
|
import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
|
||||||
import 'package:marco/helpers/utils/base_bottom_sheet.dart';
|
import 'package:marco/helpers/utils/base_bottom_sheet.dart';
|
||||||
@ -57,14 +58,22 @@ class _PaymentRequestBottomSheetState extends State<_PaymentRequestBottomSheet>
|
|||||||
if (widget.isEdit && widget.existingData != null) {
|
if (widget.isEdit && widget.existingData != null) {
|
||||||
final data = widget.existingData!;
|
final data = widget.existingData!;
|
||||||
|
|
||||||
// 🧩 Prefill basic text fields
|
// Prefill text fields
|
||||||
controller.titleController.text = data["title"] ?? "";
|
controller.titleController.text = data["title"] ?? "";
|
||||||
controller.amountController.text = data["amount"]?.toString() ?? "";
|
controller.amountController.text = data["amount"]?.toString() ?? "";
|
||||||
controller.descriptionController.text = data["description"] ?? "";
|
controller.descriptionController.text = data["description"] ?? "";
|
||||||
controller.dueDateController.text =
|
|
||||||
data["dueDate"]?.toString().split(" ")[0] ?? "";
|
|
||||||
|
|
||||||
// 🧩 Prefill dropdowns & toggles
|
// Prefill due date
|
||||||
|
if (data["dueDate"] != null && data["dueDate"].toString().isNotEmpty) {
|
||||||
|
DateTime? dueDate = DateTime.tryParse(data["dueDate"].toString());
|
||||||
|
if (dueDate != null) {
|
||||||
|
controller.selectedDueDate.value = dueDate;
|
||||||
|
controller.dueDateController.text =
|
||||||
|
DateFormat('dd MMM yyyy').format(dueDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefill dropdowns & toggles
|
||||||
controller.selectedProject.value = {
|
controller.selectedProject.value = {
|
||||||
'id': data["projectId"],
|
'id': data["projectId"],
|
||||||
'name': data["projectName"],
|
'name': data["projectName"],
|
||||||
@ -72,7 +81,7 @@ class _PaymentRequestBottomSheetState extends State<_PaymentRequestBottomSheet>
|
|||||||
controller.selectedPayee.value = data["payee"] ?? "";
|
controller.selectedPayee.value = data["payee"] ?? "";
|
||||||
controller.isAdvancePayment.value = data["isAdvancePayment"] ?? false;
|
controller.isAdvancePayment.value = data["isAdvancePayment"] ?? false;
|
||||||
|
|
||||||
// 🕒 Wait until categories & currencies are loaded before setting them
|
// Categories & currencies
|
||||||
everAll([controller.categories, controller.currencies], (_) {
|
everAll([controller.categories, controller.currencies], (_) {
|
||||||
controller.selectedCategory.value = controller.categories
|
controller.selectedCategory.value = controller.categories
|
||||||
.firstWhereOrNull((c) => c.id == data["expenseCategoryId"]);
|
.firstWhereOrNull((c) => c.id == data["expenseCategoryId"]);
|
||||||
@ -80,7 +89,7 @@ class _PaymentRequestBottomSheetState extends State<_PaymentRequestBottomSheet>
|
|||||||
.firstWhereOrNull((c) => c.id == data["currencyId"]);
|
.firstWhereOrNull((c) => c.id == data["currencyId"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 🖇 Attachments
|
// Attachments
|
||||||
final attachmentsData = data["attachments"];
|
final attachmentsData = data["attachments"];
|
||||||
if (attachmentsData != null &&
|
if (attachmentsData != null &&
|
||||||
attachmentsData is List &&
|
attachmentsData is List &&
|
||||||
@ -88,13 +97,13 @@ class _PaymentRequestBottomSheetState extends State<_PaymentRequestBottomSheet>
|
|||||||
final attachments = attachmentsData
|
final attachments = attachmentsData
|
||||||
.whereType<Map<String, dynamic>>()
|
.whereType<Map<String, dynamic>>()
|
||||||
.map((a) => {
|
.map((a) => {
|
||||||
"id": a["documentId"] ?? a["id"], // map documentId to id
|
"id": a["documentId"] ?? a["id"],
|
||||||
"fileName": a["fileName"],
|
"fileName": a["fileName"],
|
||||||
"url": a["url"],
|
"url": a["url"],
|
||||||
"thumbUrl": a["thumbUrl"],
|
"thumbUrl": a["thumbUrl"],
|
||||||
"fileSize": a["fileSize"] ?? 0,
|
"fileSize": a["fileSize"] ?? 0,
|
||||||
"contentType": a["contentType"] ?? "",
|
"contentType": a["contentType"] ?? "",
|
||||||
"isActive": true, // ensure active by default
|
"isActive": true,
|
||||||
})
|
})
|
||||||
.toList();
|
.toList();
|
||||||
controller.existingAttachments.assignAll(attachments);
|
controller.existingAttachments.assignAll(attachments);
|
||||||
@ -104,6 +113,7 @@ class _PaymentRequestBottomSheetState extends State<_PaymentRequestBottomSheet>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Obx(() => Form(
|
return Obx(() => Form(
|
||||||
@ -117,7 +127,7 @@ class _PaymentRequestBottomSheetState extends State<_PaymentRequestBottomSheet>
|
|||||||
submitText: "Save as Draft",
|
submitText: "Save as Draft",
|
||||||
onSubmit: () async {
|
onSubmit: () async {
|
||||||
if (_formKey.currentState!.validate() && _validateSelections()) {
|
if (_formKey.currentState!.validate() && _validateSelections()) {
|
||||||
bool success = false;
|
bool success = false;
|
||||||
if (widget.isEdit && widget.existingData != null) {
|
if (widget.isEdit && widget.existingData != null) {
|
||||||
final requestId =
|
final requestId =
|
||||||
widget.existingData!['id']?.toString() ?? '';
|
widget.existingData!['id']?.toString() ?? '';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user