From 4d11a2ccf0833ee27a4ff8e8c7f269a2fcf62322 Mon Sep 17 00:00:00 2001 From: Vaibhav Surve Date: Fri, 5 Sep 2025 16:22:05 +0530 Subject: [PATCH] feat: Simplify document upload by removing initial data handling and existing file name references --- .../document_upload_bottom_sheet.dart | 79 +------------------ 1 file changed, 3 insertions(+), 76 deletions(-) diff --git a/lib/model/document/document_upload_bottom_sheet.dart b/lib/model/document/document_upload_bottom_sheet.dart index 94b9d24..7876abb 100644 --- a/lib/model/document/document_upload_bottom_sheet.dart +++ b/lib/model/document/document_upload_bottom_sheet.dart @@ -13,12 +13,10 @@ import 'package:marco/helpers/widgets/my_snackbar.dart'; class DocumentUploadBottomSheet extends StatefulWidget { final Function(Map) onSubmit; - final Map? initialData; const DocumentUploadBottomSheet({ Key? key, required this.onSubmit, - this.initialData, }) : super(key: key); @override @@ -35,55 +33,6 @@ class _DocumentUploadBottomSheetState extends State { final TextEditingController _descriptionController = TextEditingController(); File? selectedFile; - String? existingFileName; - - @override - void initState() { - super.initState(); - - // ✅ Pre-fill if editing - if (widget.initialData != null) { - final data = widget.initialData!; - _docIdController.text = data["documentId"] ?? ""; - _docNameController.text = data["name"] ?? ""; - _descriptionController.text = data["description"] ?? ""; - - existingFileName = data["fileName"]; - - // Preselect category & type - WidgetsBinding.instance.addPostFrameCallback((_) async { - if (data["categoryName"] != null) { - final category = controller.categories.firstWhereOrNull( - (c) => c.name == data["categoryName"], - ); - if (category != null) { - setState(() => controller.selectedCategory = category); - await controller.fetchDocumentTypes(category.id); - - if (data["documentTypeName"] != null) { - final type = controller.documentTypes.firstWhereOrNull( - (t) => t.name == data["documentTypeName"], - ); - if (type != null) { - setState(() => controller.selectedType = type); - } - } - } - } - }); - - // Prefill tags - if (data["tags"] != null) { - controller.enteredTags.value = - List.from(data["tags"].map((t) => t["name"])); - } - - // Prefill file info - controller.selectedFileName = data["fileName"]; - controller.selectedFileContentType = data["contentType"]; - controller.selectedFileSize = data["fileSize"]; - } - } @override void dispose() { @@ -96,7 +45,7 @@ class _DocumentUploadBottomSheetState extends State { void _handleSubmit() { if (!(_formKey.currentState?.validate() ?? false)) return; - if (selectedFile == null && existingFileName == null) { + if (selectedFile == null) { showAppSnackbar( title: "Error", message: "Please attach a document", @@ -173,7 +122,6 @@ class _DocumentUploadBottomSheetState extends State { setState(() { selectedFile = file; - existingFileName = null; controller.selectedFileName = fileName; controller.selectedFileBase64 = base64Data; controller.selectedFileContentType = @@ -188,7 +136,7 @@ class _DocumentUploadBottomSheetState extends State { @override Widget build(BuildContext context) { return BaseBottomSheet( - title: widget.initialData == null ? "Upload Document" : "Edit Document", + title: "Upload Document", onCancel: () => Navigator.pop(context), onSubmit: _handleSubmit, child: Form( @@ -267,11 +215,9 @@ class _DocumentUploadBottomSheetState extends State { /// Single Attachment Section AttachmentSectionSingle( attachment: selectedFile, - existingFileName: existingFileName, onPick: _pickFile, onRemove: () => setState(() { selectedFile = null; - existingFileName = null; controller.selectedFileName = null; controller.selectedFileBase64 = null; controller.selectedFileContentType = null; @@ -392,38 +338,18 @@ class _DocumentUploadBottomSheetState extends State { /// ---------------- Single Attachment Widget ---------------- class AttachmentSectionSingle extends StatelessWidget { final File? attachment; - final String? existingFileName; // ✅ new final VoidCallback onPick; final VoidCallback? onRemove; const AttachmentSectionSingle({ Key? key, this.attachment, - this.existingFileName, required this.onPick, this.onRemove, }) : super(key: key); @override Widget build(BuildContext context) { - if (attachment == null && existingFileName != null) { - return Row( - children: [ - const Icon(Icons.insert_drive_file, color: Colors.blueAccent), - const SizedBox(width: 8), - Expanded( - child: Text(existingFileName!, - style: const TextStyle(fontSize: 14, color: Colors.black87)), - ), - if (onRemove != null) - IconButton( - icon: const Icon(Icons.close, color: Colors.red), - onPressed: onRemove, - ), - ], - ); - } - final allowedImageExtensions = ['jpg', 'jpeg', 'png']; Widget buildTile(File file) { @@ -553,6 +479,7 @@ class AttachmentSectionSingle extends StatelessWidget { } } + // ---- Reusable Widgets ---- class LabeledInput extends StatelessWidget {