feat(directory): integrate NotesController in DirectoryMainScreen and improve code formatting in NotesView
This commit is contained in:
parent
5e8158a410
commit
43aeec4c6f
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'package:marco/controller/directory/directory_controller.dart';
|
||||
import 'package:marco/controller/directory/notes_controller.dart';
|
||||
import 'package:marco/controller/project_controller.dart';
|
||||
import 'package:marco/helpers/widgets/my_spacing.dart';
|
||||
import 'package:marco/helpers/widgets/my_text.dart';
|
||||
@ -13,6 +14,7 @@ class DirectoryMainScreen extends StatelessWidget {
|
||||
DirectoryMainScreen({super.key});
|
||||
|
||||
final DirectoryController controller = Get.put(DirectoryController());
|
||||
final NotesController notesController = Get.put(NotesController());
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -49,8 +51,8 @@ class DirectoryMainScreen extends StatelessWidget {
|
||||
MySpacing.height(2),
|
||||
GetBuilder<ProjectController>(
|
||||
builder: (projectController) {
|
||||
final projectName = projectController
|
||||
.selectedProject?.name ??
|
||||
final projectName =
|
||||
projectController.selectedProject?.name ??
|
||||
'Select Project';
|
||||
return Row(
|
||||
children: [
|
||||
@ -111,9 +113,8 @@ class DirectoryMainScreen extends StatelessWidget {
|
||||
|
||||
// Main View
|
||||
Expanded(
|
||||
child: Obx(() => controller.isNotesView.value
|
||||
? NotesView()
|
||||
: DirectoryView()),
|
||||
child: Obx(() =>
|
||||
controller.isNotesView.value ? NotesView() : DirectoryView()),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -87,7 +87,8 @@ class NotesView extends StatelessWidget {
|
||||
onChanged: (value) => controller.searchQuery.value = value,
|
||||
decoration: InputDecoration(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
prefixIcon: const Icon(Icons.search, size: 20, color: Colors.grey),
|
||||
prefixIcon: const Icon(Icons.search,
|
||||
size: 20, color: Colors.grey),
|
||||
hintText: 'Search notes...',
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
@ -136,7 +137,8 @@ class NotesView extends StatelessWidget {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.note_alt_outlined, size: 60, color: Colors.grey),
|
||||
const Icon(Icons.note_alt_outlined,
|
||||
size: 60, color: Colors.grey),
|
||||
const SizedBox(height: 12),
|
||||
MyText.bodyMedium('No notes found.', fontWeight: 500),
|
||||
],
|
||||
@ -150,20 +152,33 @@ class NotesView extends StatelessWidget {
|
||||
separatorBuilder: (_, __) => MySpacing.height(12),
|
||||
itemBuilder: (_, index) {
|
||||
final note = notes[index];
|
||||
|
||||
return Obx(() {
|
||||
final isEditing = controller.editingNoteId.value == note.id;
|
||||
|
||||
final initials = note.contactName.trim().isNotEmpty
|
||||
? note.contactName.trim().split(' ').map((e) => e[0]).take(2).join().toUpperCase()
|
||||
? note.contactName
|
||||
.trim()
|
||||
.split(' ')
|
||||
.map((e) => e[0])
|
||||
.take(2)
|
||||
.join()
|
||||
.toUpperCase()
|
||||
: "NA";
|
||||
|
||||
final createdDate = DateTimeUtils.convertUtcToLocal(note.createdAt.toString(), format: 'dd MMM yyyy');
|
||||
final createdTime = DateTimeUtils.convertUtcToLocal(note.createdAt.toString(), format: 'hh:mm a');
|
||||
final createdDate = DateTimeUtils.convertUtcToLocal(
|
||||
note.createdAt.toString(),
|
||||
format: 'dd MMM yyyy');
|
||||
final createdTime = DateTimeUtils.convertUtcToLocal(
|
||||
note.createdAt.toString(),
|
||||
format: 'hh:mm a');
|
||||
|
||||
final decodedDelta = HtmlToDelta().convert(note.note);
|
||||
final quillController = isEditing
|
||||
? quill.QuillController(
|
||||
document: quill.Document.fromDelta(decodedDelta),
|
||||
selection: TextSelection.collapsed(offset: decodedDelta.length),
|
||||
selection: TextSelection.collapsed(
|
||||
offset: decodedDelta.length),
|
||||
)
|
||||
: null;
|
||||
|
||||
@ -178,7 +193,10 @@ class NotesView extends StatelessWidget {
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [
|
||||
BoxShadow(color: Colors.black12, blurRadius: 4, offset: Offset(0, 2)),
|
||||
BoxShadow(
|
||||
color: Colors.black12,
|
||||
blurRadius: 4,
|
||||
offset: Offset(0, 2)),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
@ -214,7 +232,8 @@ class NotesView extends StatelessWidget {
|
||||
size: 20,
|
||||
),
|
||||
onPressed: () {
|
||||
controller.editingNoteId.value = isEditing ? null : note.id;
|
||||
controller.editingNoteId.value =
|
||||
isEditing ? null : note.id;
|
||||
},
|
||||
),
|
||||
],
|
||||
@ -226,7 +245,8 @@ class NotesView extends StatelessWidget {
|
||||
if (isEditing && quillController != null)
|
||||
CommentEditorCard(
|
||||
controller: quillController,
|
||||
onCancel: () => controller.editingNoteId.value = null,
|
||||
onCancel: () =>
|
||||
controller.editingNoteId.value = null,
|
||||
onSave: (quillCtrl) async {
|
||||
final delta = quillCtrl.document.toDelta();
|
||||
final htmlOutput = _convertDeltaToHtml(delta);
|
||||
@ -250,6 +270,7 @@ class NotesView extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
}),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user