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:get/get.dart';
|
||||||
|
|
||||||
import 'package:marco/controller/directory/directory_controller.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/controller/project_controller.dart';
|
||||||
import 'package:marco/helpers/widgets/my_spacing.dart';
|
import 'package:marco/helpers/widgets/my_spacing.dart';
|
||||||
import 'package:marco/helpers/widgets/my_text.dart';
|
import 'package:marco/helpers/widgets/my_text.dart';
|
||||||
@ -13,6 +14,7 @@ class DirectoryMainScreen extends StatelessWidget {
|
|||||||
DirectoryMainScreen({super.key});
|
DirectoryMainScreen({super.key});
|
||||||
|
|
||||||
final DirectoryController controller = Get.put(DirectoryController());
|
final DirectoryController controller = Get.put(DirectoryController());
|
||||||
|
final NotesController notesController = Get.put(NotesController());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -49,9 +51,9 @@ class DirectoryMainScreen extends StatelessWidget {
|
|||||||
MySpacing.height(2),
|
MySpacing.height(2),
|
||||||
GetBuilder<ProjectController>(
|
GetBuilder<ProjectController>(
|
||||||
builder: (projectController) {
|
builder: (projectController) {
|
||||||
final projectName = projectController
|
final projectName =
|
||||||
.selectedProject?.name ??
|
projectController.selectedProject?.name ??
|
||||||
'Select Project';
|
'Select Project';
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.work_outline,
|
const Icon(Icons.work_outline,
|
||||||
@ -111,9 +113,8 @@ class DirectoryMainScreen extends StatelessWidget {
|
|||||||
|
|
||||||
// Main View
|
// Main View
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Obx(() => controller.isNotesView.value
|
child: Obx(() =>
|
||||||
? NotesView()
|
controller.isNotesView.value ? NotesView() : DirectoryView()),
|
||||||
: DirectoryView()),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@ -87,7 +87,8 @@ class NotesView extends StatelessWidget {
|
|||||||
onChanged: (value) => controller.searchQuery.value = value,
|
onChanged: (value) => controller.searchQuery.value = value,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 6),
|
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...',
|
hintText: 'Search notes...',
|
||||||
filled: true,
|
filled: true,
|
||||||
fillColor: Colors.white,
|
fillColor: Colors.white,
|
||||||
@ -136,7 +137,8 @@ class NotesView extends StatelessWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
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),
|
const SizedBox(height: 12),
|
||||||
MyText.bodyMedium('No notes found.', fontWeight: 500),
|
MyText.bodyMedium('No notes found.', fontWeight: 500),
|
||||||
],
|
],
|
||||||
@ -150,106 +152,125 @@ class NotesView extends StatelessWidget {
|
|||||||
separatorBuilder: (_, __) => MySpacing.height(12),
|
separatorBuilder: (_, __) => MySpacing.height(12),
|
||||||
itemBuilder: (_, index) {
|
itemBuilder: (_, index) {
|
||||||
final note = notes[index];
|
final note = notes[index];
|
||||||
final isEditing = controller.editingNoteId.value == note.id;
|
|
||||||
|
|
||||||
final initials = note.contactName.trim().isNotEmpty
|
return Obx(() {
|
||||||
? note.contactName.trim().split(' ').map((e) => e[0]).take(2).join().toUpperCase()
|
final isEditing = controller.editingNoteId.value == note.id;
|
||||||
: "NA";
|
|
||||||
|
|
||||||
final createdDate = DateTimeUtils.convertUtcToLocal(note.createdAt.toString(), format: 'dd MMM yyyy');
|
final initials = note.contactName.trim().isNotEmpty
|
||||||
final createdTime = DateTimeUtils.convertUtcToLocal(note.createdAt.toString(), format: 'hh:mm a');
|
? note.contactName
|
||||||
|
.trim()
|
||||||
|
.split(' ')
|
||||||
|
.map((e) => e[0])
|
||||||
|
.take(2)
|
||||||
|
.join()
|
||||||
|
.toUpperCase()
|
||||||
|
: "NA";
|
||||||
|
|
||||||
final decodedDelta = HtmlToDelta().convert(note.note);
|
final createdDate = DateTimeUtils.convertUtcToLocal(
|
||||||
final quillController = isEditing
|
note.createdAt.toString(),
|
||||||
? quill.QuillController(
|
format: 'dd MMM yyyy');
|
||||||
document: quill.Document.fromDelta(decodedDelta),
|
final createdTime = DateTimeUtils.convertUtcToLocal(
|
||||||
selection: TextSelection.collapsed(offset: decodedDelta.length),
|
note.createdAt.toString(),
|
||||||
)
|
format: 'hh:mm a');
|
||||||
: null;
|
|
||||||
|
|
||||||
return AnimatedContainer(
|
final decodedDelta = HtmlToDelta().convert(note.note);
|
||||||
duration: const Duration(milliseconds: 250),
|
final quillController = isEditing
|
||||||
padding: MySpacing.xy(12, 12),
|
? quill.QuillController(
|
||||||
decoration: BoxDecoration(
|
document: quill.Document.fromDelta(decodedDelta),
|
||||||
color: isEditing ? Colors.indigo[50] : Colors.white,
|
selection: TextSelection.collapsed(
|
||||||
border: Border.all(
|
offset: decodedDelta.length),
|
||||||
color: isEditing ? Colors.indigo : Colors.grey.shade300,
|
)
|
||||||
width: 1.1,
|
: null;
|
||||||
|
|
||||||
|
return AnimatedContainer(
|
||||||
|
duration: const Duration(milliseconds: 250),
|
||||||
|
padding: MySpacing.xy(12, 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: isEditing ? Colors.indigo[50] : Colors.white,
|
||||||
|
border: Border.all(
|
||||||
|
color: isEditing ? Colors.indigo : Colors.grey.shade300,
|
||||||
|
width: 1.1,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
boxShadow: const [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black12,
|
||||||
|
blurRadius: 4,
|
||||||
|
offset: Offset(0, 2)),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
borderRadius: BorderRadius.circular(12),
|
child: Column(
|
||||||
boxShadow: const [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
BoxShadow(color: Colors.black12, blurRadius: 4, offset: Offset(0, 2)),
|
children: [
|
||||||
],
|
/// Header Row
|
||||||
),
|
Row(
|
||||||
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
children: [
|
Avatar(firstName: initials, lastName: '', size: 40),
|
||||||
/// Header Row
|
MySpacing.width(12),
|
||||||
Row(
|
Expanded(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
child: Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
Avatar(firstName: initials, lastName: '', size: 40),
|
children: [
|
||||||
MySpacing.width(12),
|
MyText.titleSmall(
|
||||||
Expanded(
|
"${note.contactName} (${note.organizationName})",
|
||||||
child: Column(
|
fontWeight: 600,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
overflow: TextOverflow.ellipsis,
|
||||||
children: [
|
color: Colors.indigo[800],
|
||||||
MyText.titleSmall(
|
),
|
||||||
"${note.contactName} (${note.organizationName})",
|
MyText.bodySmall(
|
||||||
fontWeight: 600,
|
"by ${note.createdBy.firstName} • $createdDate, $createdTime",
|
||||||
overflow: TextOverflow.ellipsis,
|
color: Colors.grey[600],
|
||||||
color: Colors.indigo[800],
|
),
|
||||||
),
|
],
|
||||||
MyText.bodySmall(
|
),
|
||||||
"by ${note.createdBy.firstName} • $createdDate, $createdTime",
|
|
||||||
color: Colors.grey[600],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
IconButton(
|
||||||
IconButton(
|
icon: Icon(
|
||||||
icon: Icon(
|
isEditing ? Icons.close : Icons.edit,
|
||||||
isEditing ? Icons.close : Icons.edit,
|
color: Colors.indigo,
|
||||||
color: Colors.indigo,
|
size: 20,
|
||||||
size: 20,
|
),
|
||||||
|
onPressed: () {
|
||||||
|
controller.editingNoteId.value =
|
||||||
|
isEditing ? null : note.id;
|
||||||
|
},
|
||||||
),
|
),
|
||||||
onPressed: () {
|
],
|
||||||
controller.editingNoteId.value = isEditing ? null : note.id;
|
),
|
||||||
|
|
||||||
|
MySpacing.height(12),
|
||||||
|
|
||||||
|
/// Content
|
||||||
|
if (isEditing && quillController != null)
|
||||||
|
CommentEditorCard(
|
||||||
|
controller: quillController,
|
||||||
|
onCancel: () =>
|
||||||
|
controller.editingNoteId.value = null,
|
||||||
|
onSave: (quillCtrl) async {
|
||||||
|
final delta = quillCtrl.document.toDelta();
|
||||||
|
final htmlOutput = _convertDeltaToHtml(delta);
|
||||||
|
final updated = note.copyWith(note: htmlOutput);
|
||||||
|
await controller.updateNote(updated);
|
||||||
|
controller.editingNoteId.value = null;
|
||||||
|
},
|
||||||
|
)
|
||||||
|
else
|
||||||
|
html.Html(
|
||||||
|
data: note.note,
|
||||||
|
style: {
|
||||||
|
"body": html.Style(
|
||||||
|
margin: html.Margins.zero,
|
||||||
|
padding: html.HtmlPaddings.zero,
|
||||||
|
fontSize: html.FontSize.medium,
|
||||||
|
color: Colors.black87,
|
||||||
|
),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
);
|
||||||
MySpacing.height(12),
|
});
|
||||||
|
|
||||||
/// Content
|
|
||||||
if (isEditing && quillController != null)
|
|
||||||
CommentEditorCard(
|
|
||||||
controller: quillController,
|
|
||||||
onCancel: () => controller.editingNoteId.value = null,
|
|
||||||
onSave: (quillCtrl) async {
|
|
||||||
final delta = quillCtrl.document.toDelta();
|
|
||||||
final htmlOutput = _convertDeltaToHtml(delta);
|
|
||||||
final updated = note.copyWith(note: htmlOutput);
|
|
||||||
await controller.updateNote(updated);
|
|
||||||
controller.editingNoteId.value = null;
|
|
||||||
},
|
|
||||||
)
|
|
||||||
else
|
|
||||||
html.Html(
|
|
||||||
data: note.note,
|
|
||||||
style: {
|
|
||||||
"body": html.Style(
|
|
||||||
margin: html.Margins.zero,
|
|
||||||
padding: html.HtmlPaddings.zero,
|
|
||||||
fontSize: html.FontSize.medium,
|
|
||||||
color: Colors.black87,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user