Dynamic edit and Add expense title
This commit is contained in:
parent
0acd619d78
commit
0401b41b3c
@ -10,15 +10,27 @@ import 'package:url_launcher/url_launcher_string.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/helpers/widgets/image_viewer_dialog.dart';
|
||||
|
||||
Future<T?> showAddExpenseBottomSheet<T>() {
|
||||
Future<T?> showAddExpenseBottomSheet<T>({
|
||||
bool isEdit = false,
|
||||
Map<String, dynamic>? existingExpense,
|
||||
}) {
|
||||
return Get.bottomSheet<T>(
|
||||
const _AddExpenseBottomSheet(),
|
||||
_AddExpenseBottomSheet(
|
||||
isEdit: isEdit,
|
||||
existingExpense: existingExpense,
|
||||
),
|
||||
isScrollControlled: true,
|
||||
);
|
||||
}
|
||||
|
||||
class _AddExpenseBottomSheet extends StatefulWidget {
|
||||
const _AddExpenseBottomSheet();
|
||||
final bool isEdit;
|
||||
final Map<String, dynamic>? existingExpense;
|
||||
|
||||
const _AddExpenseBottomSheet({
|
||||
this.isEdit = false,
|
||||
this.existingExpense,
|
||||
});
|
||||
|
||||
@override
|
||||
State<_AddExpenseBottomSheet> createState() => _AddExpenseBottomSheetState();
|
||||
@ -91,7 +103,7 @@ class _AddExpenseBottomSheetState extends State<_AddExpenseBottomSheet> {
|
||||
Widget build(BuildContext context) {
|
||||
return Obx(() {
|
||||
return BaseBottomSheet(
|
||||
title: "Add Expense",
|
||||
title: widget.isEdit ? "Edit Expense" : "Add Expense",
|
||||
isSubmitting: controller.isSubmitting.value,
|
||||
onCancel: Get.back,
|
||||
onSubmit: () {
|
||||
@ -485,7 +497,8 @@ class _AttachmentsSection extends StatelessWidget {
|
||||
runSpacing: 8,
|
||||
children: existingAttachments.map((doc) {
|
||||
final isImage =
|
||||
doc['contentType']?.toString().startsWith('image/') ?? false;
|
||||
doc['contentType']?.toString().startsWith('image/') ??
|
||||
false;
|
||||
final url = doc['url'];
|
||||
final fileName = doc['fileName'] ?? 'Unnamed';
|
||||
|
||||
@ -501,11 +514,13 @@ class _AttachmentsSection extends StatelessWidget {
|
||||
.startsWith('image/') ??
|
||||
false))
|
||||
.toList();
|
||||
final initialIndex = imageDocs.indexWhere((d) => d == doc);
|
||||
final initialIndex =
|
||||
imageDocs.indexWhere((d) => d == doc);
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => ImageViewerDialog(
|
||||
imageSources: imageDocs.map((e) => e['url']).toList(),
|
||||
imageSources:
|
||||
imageDocs.map((e) => e['url']).toList(),
|
||||
initialIndex: initialIndex,
|
||||
),
|
||||
);
|
||||
@ -540,7 +555,8 @@ class _AttachmentsSection extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: 7),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 120),
|
||||
constraints:
|
||||
const BoxConstraints(maxWidth: 120),
|
||||
child: Text(
|
||||
fileName,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@ -556,7 +572,8 @@ class _AttachmentsSection extends StatelessWidget {
|
||||
top: -6,
|
||||
right: -6,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.close, color: Colors.red, size: 18),
|
||||
icon: const Icon(Icons.close,
|
||||
color: Colors.red, size: 18),
|
||||
onPressed: () => onRemoveExisting!(doc),
|
||||
),
|
||||
),
|
||||
|
@ -146,7 +146,7 @@ class ExpenseDetailScreen extends StatelessWidget {
|
||||
await addCtrl.loadMasterData();
|
||||
addCtrl.populateFieldsForEdit(editData);
|
||||
|
||||
await showAddExpenseBottomSheet();
|
||||
await showAddExpenseBottomSheet( isEdit: true,);
|
||||
|
||||
// Refresh expense details after editing
|
||||
await controller.fetchExpenseDetails();
|
||||
|
Loading…
x
Reference in New Issue
Block a user