fixed the issue when user licks on comment same multiple taps duplicate comments creating
This commit is contained in:
parent
a6da579f07
commit
c9882879ff
@ -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<void> Function(quill.QuillController controller) onSave;
|
||||
@ -13,13 +14,31 @@ class CommentEditorCard extends StatelessWidget {
|
||||
required this.onSave,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CommentEditorCard> createState() => _CommentEditorCardState();
|
||||
}
|
||||
|
||||
class _CommentEditorCardState extends State<CommentEditorCard> {
|
||||
bool _isSubmitting = false;
|
||||
|
||||
Future<void> _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),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user