From c9882879ff09c5ece6676c9bc5e46a4a923af3d5 Mon Sep 17 00:00:00 2001 From: Vaibhav Surve Date: Sat, 16 Aug 2025 17:01:58 +0530 Subject: [PATCH] fixed the issue when user licks on comment same multiple taps duplicate comments creating --- .../Directory/comment_editor_card.dart | 85 +++++++++++++------ 1 file changed, 61 insertions(+), 24 deletions(-) diff --git a/lib/helpers/widgets/Directory/comment_editor_card.dart b/lib/helpers/widgets/Directory/comment_editor_card.dart index 64a712d..c6125af 100644 --- a/lib/helpers/widgets/Directory/comment_editor_card.dart +++ b/lib/helpers/widgets/Directory/comment_editor_card.dart @@ -1,7 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_quill/flutter_quill.dart' as quill; +import 'package:marco/helpers/widgets/my_text.dart'; -class CommentEditorCard extends StatelessWidget { +class CommentEditorCard extends StatefulWidget { final quill.QuillController controller; final VoidCallback onCancel; final Future Function(quill.QuillController controller) onSave; @@ -13,13 +14,31 @@ class CommentEditorCard extends StatelessWidget { required this.onSave, }); + @override + State createState() => _CommentEditorCardState(); +} + +class _CommentEditorCardState extends State { + bool _isSubmitting = false; + + Future _handleSave() async { + if (_isSubmitting) return; + setState(() => _isSubmitting = true); + + try { + await widget.onSave(widget.controller); + } finally { + if (mounted) setState(() => _isSubmitting = false); + } + } + @override Widget build(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ quill.QuillSimpleToolbar( - controller: controller, + controller: widget.controller, configurations: const quill.QuillSimpleToolbarConfigurations( showBoldButton: true, showItalicButton: true, @@ -48,7 +67,7 @@ class CommentEditorCard extends StatelessWidget { multiRowsDisplay: false, ), ), - const SizedBox(height: 38), + const SizedBox(height: 24), Container( height: 140, padding: const EdgeInsets.all(8), @@ -58,7 +77,7 @@ class CommentEditorCard extends StatelessWidget { color: const Color(0xFFFDFDFD), ), child: quill.QuillEditor.basic( - controller: controller, + controller: widget.controller, configurations: const quill.QuillEditorConfigurations( autoFocus: true, expands: false, @@ -66,32 +85,50 @@ class CommentEditorCard extends StatelessWidget { ), ), ), - const SizedBox(height: 8), - Align( - alignment: Alignment.centerRight, - child: Wrap( - spacing: 8, - children: [ - OutlinedButton.icon( - onPressed: onCancel, - icon: const Icon(Icons.close, size: 18), - label: const Text("Cancel"), - style: OutlinedButton.styleFrom( - foregroundColor: Colors.grey[700], + const SizedBox(height: 16), + + // 👇 Buttons same as BaseBottomSheet + Row( + children: [ + Expanded( + child: ElevatedButton.icon( + onPressed: _isSubmitting ? null : widget.onCancel, + icon: const Icon(Icons.close, color: Colors.white), + label: MyText.bodyMedium( + "Cancel", + color: Colors.white, + fontWeight: 600, + ), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.grey, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + padding: const EdgeInsets.symmetric(vertical: 8), ), ), - ElevatedButton.icon( - onPressed: () => onSave(controller), - icon: const Icon(Icons.save, size: 18), - label: const Text("Save"), + ), + const SizedBox(width: 12), + Expanded( + child: ElevatedButton.icon( + onPressed: _isSubmitting ? null : _handleSave, + icon: const Icon(Icons.check_circle_outline, color: Colors.white), + label: MyText.bodyMedium( + _isSubmitting ? "Submitting..." : "Submit", + color: Colors.white, + fontWeight: 600, + ), style: ElevatedButton.styleFrom( backgroundColor: Colors.indigo, - foregroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + padding: const EdgeInsets.symmetric(vertical: 8), ), ), - ], - ), - ) + ), + ], + ), ], ); }