73 lines
1.8 KiB
Dart
73 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:marco/controller/directory/add_comment_controller.dart';
|
|
import 'package:marco/helpers/utils/base_bottom_sheet.dart';
|
|
|
|
class AddCommentBottomSheet extends StatefulWidget {
|
|
final String contactId;
|
|
|
|
const AddCommentBottomSheet({super.key, required this.contactId});
|
|
|
|
@override
|
|
State<AddCommentBottomSheet> createState() => _AddCommentBottomSheetState();
|
|
}
|
|
|
|
class _AddCommentBottomSheetState extends State<AddCommentBottomSheet> {
|
|
late final AddCommentController controller;
|
|
final TextEditingController textController = TextEditingController();
|
|
bool isSubmitting = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
controller = Get.put(AddCommentController(contactId: widget.contactId));
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
textController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> handleSubmit() async {
|
|
final noteText = textController.text.trim();
|
|
if (noteText.isEmpty) return;
|
|
|
|
setState(() {
|
|
isSubmitting = true;
|
|
});
|
|
|
|
controller.updateNote(noteText);
|
|
await controller.submitComment();
|
|
|
|
if (mounted) {
|
|
setState(() {
|
|
isSubmitting = false;
|
|
});
|
|
Get.back(result: true);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BaseBottomSheet(
|
|
title: "Add Note",
|
|
onCancel: () => Get.back(),
|
|
onSubmit: handleSubmit,
|
|
isSubmitting: isSubmitting,
|
|
child: TextField(
|
|
controller: textController,
|
|
maxLines: null,
|
|
minLines: 5,
|
|
decoration: InputDecoration(
|
|
hintText: "Enter your note here...",
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
contentPadding: const EdgeInsets.all(12),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|