feat: Enhance SearchAppBar with debounce and customizable padding
- Added debounce functionality for search input in SearchAppBar to improve performance. - Introduced a controller parameter to allow external control of the search input. - Made padding customizable via a new padding parameter. - Improved leading button handling with an option to show/hide it. feat: Implement Category Editor Dialog - Created a new CategoryEditorDialog widget for editing category details. - Allows users to set category name, color, and icon with a preview. - Supports creating new categories with a confirmation dialog. feat: Add Category Menu Button - Introduced CategoryMenuButton for selecting categories with an option to create new ones. - Displays a menu with existing categories and allows editing. - Supports dynamic background color based on active state. feat: Create Note List View - Added NoteListView widget for displaying a list of notes with reordering capability. - Integrates refresh functionality and displays last sync time. - Supports selection and deletion of notes with visual feedback.
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'package:notas/models/category.dart';
|
||||
import 'package:notas/models/note.dart';
|
||||
import 'package:notas/theme/app_palette.dart';
|
||||
import 'package:notas/widgets/note_card.dart';
|
||||
|
||||
class NoteListView extends StatelessWidget {
|
||||
const NoteListView({
|
||||
super.key,
|
||||
required this.notes,
|
||||
required this.isLoading,
|
||||
required this.selectedNoteId,
|
||||
required this.showSelectionBorder,
|
||||
required this.categoryForNote,
|
||||
required this.lastSyncAt,
|
||||
required this.onRefresh,
|
||||
required this.onReorder,
|
||||
required this.onNoteTap,
|
||||
required this.onDeleteNote,
|
||||
required this.onChangeCategory,
|
||||
});
|
||||
|
||||
final List<Note> notes;
|
||||
final bool isLoading;
|
||||
final String? selectedNoteId;
|
||||
final bool showSelectionBorder;
|
||||
final Category? Function(String? categoryId) categoryForNote;
|
||||
final DateTime? lastSyncAt;
|
||||
final Future<void> Function() onRefresh;
|
||||
final Future<void> Function(int oldIndex, int newIndex) onReorder;
|
||||
final void Function(Note note) onNoteTap;
|
||||
final Future<void> Function(Note note) onDeleteNote;
|
||||
final Future<void> Function(BuildContext buttonContext, Note note)
|
||||
onChangeCategory;
|
||||
|
||||
String _formatLastSyncAt() {
|
||||
if (lastSyncAt == null) {
|
||||
return 'Última sincronización: nunca';
|
||||
}
|
||||
|
||||
return 'Última sincronización: ${DateFormat('dd/MM/yyyy HH:mm').format(lastSyncAt!)}';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final AppPalette palette = Theme.of(context).extension<AppPalette>() ??
|
||||
AppPalette.fromBrightness(Theme.of(context).brightness);
|
||||
|
||||
if (isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (notes.isEmpty) {
|
||||
return Center(
|
||||
child: Text(
|
||||
'No hay notas para mostrar',
|
||||
style: TextStyle(color: palette.textSecondary),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: onRefresh,
|
||||
child: ReorderableListView.builder(
|
||||
padding: const EdgeInsets.fromLTRB(10, 10, 10, 14),
|
||||
buildDefaultDragHandles: false,
|
||||
itemCount: notes.length,
|
||||
onReorderItem: onReorder,
|
||||
footer: Padding(
|
||||
padding: const EdgeInsets.only(top: 4, bottom: 72),
|
||||
child: Center(
|
||||
child: Text(
|
||||
_formatLastSyncAt(),
|
||||
style: TextStyle(color: palette.textSecondary, fontSize: 12),
|
||||
),
|
||||
),
|
||||
),
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final Note note = notes[index];
|
||||
return Padding(
|
||||
key: ValueKey<String>(note.id),
|
||||
padding: const EdgeInsets.only(bottom: 6),
|
||||
child: ReorderableDelayedDragStartListener(
|
||||
index: index,
|
||||
child: NoteCard(
|
||||
note: note,
|
||||
category: categoryForNote(note.categoryId),
|
||||
isSelected: note.id == selectedNoteId,
|
||||
showSelectionBorder: showSelectionBorder,
|
||||
onTap: () => onNoteTap(note),
|
||||
onDelete: () => onDeleteNote(note),
|
||||
onChangeCategory: (BuildContext buttonContext) =>
|
||||
onChangeCategory(buttonContext, note),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user