refactor: Improve code readability by formatting and simplifying widget structures
This commit is contained in:
@@ -86,7 +86,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
|
||||
try {
|
||||
final List<Note> notes = await widget.repository.loadNotes();
|
||||
final List<Category> categories = await widget.repository.loadCategories();
|
||||
final List<Category> categories = await widget.repository
|
||||
.loadCategories();
|
||||
final DateTime? lastSyncAt = await widget.repository.getLastSyncAt();
|
||||
|
||||
if (!mounted) {
|
||||
@@ -138,7 +139,9 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
Iterable<Note> notes = _notes;
|
||||
|
||||
if (_selectedCategoryId != null) {
|
||||
notes = notes.where((Note note) => note.categoryId == _selectedCategoryId);
|
||||
notes = notes.where(
|
||||
(Note note) => note.categoryId == _selectedCategoryId,
|
||||
);
|
||||
}
|
||||
|
||||
if (_searchQuery.isEmpty) {
|
||||
@@ -181,8 +184,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
|
||||
RelativeRect _menuRectFromContext(BuildContext anchorContext) {
|
||||
final RenderBox button = anchorContext.findRenderObject()! as RenderBox;
|
||||
final RenderBox overlay = Overlay.of(anchorContext).context.findRenderObject()!
|
||||
as RenderBox;
|
||||
final RenderBox overlay =
|
||||
Overlay.of(anchorContext).context.findRenderObject()! as RenderBox;
|
||||
final Offset topLeft = button.localToGlobal(Offset.zero, ancestor: overlay);
|
||||
final Offset bottomRight = button.localToGlobal(
|
||||
button.size.bottomRight(Offset.zero),
|
||||
@@ -190,12 +193,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
);
|
||||
|
||||
return RelativeRect.fromRect(
|
||||
Rect.fromLTRB(
|
||||
topLeft.dx,
|
||||
topLeft.dy,
|
||||
bottomRight.dx,
|
||||
bottomRight.dy,
|
||||
),
|
||||
Rect.fromLTRB(topLeft.dx, topLeft.dy, bottomRight.dx, bottomRight.dy),
|
||||
Offset.zero & overlay.size,
|
||||
);
|
||||
}
|
||||
@@ -246,7 +244,10 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _changeNoteCategory(BuildContext anchorContext, Note note) async {
|
||||
Future<void> _changeNoteCategory(
|
||||
BuildContext anchorContext,
|
||||
Note note,
|
||||
) async {
|
||||
final Category? selected = await _showAnchoredCategoryMenu<Category?>(
|
||||
anchorContext: anchorContext,
|
||||
items: <PopupMenuEntry<Category?>>[
|
||||
@@ -256,10 +257,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
for (final Category category in _categories)
|
||||
PopupMenuItem<Category?>(
|
||||
value: category,
|
||||
child: Text(category.name),
|
||||
),
|
||||
PopupMenuItem<Category?>(value: category, child: Text(category.name)),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -409,9 +407,9 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
return;
|
||||
}
|
||||
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(builder: (_) => editor),
|
||||
);
|
||||
await Navigator.of(
|
||||
context,
|
||||
).push(MaterialPageRoute<void>(builder: (_) => editor));
|
||||
}
|
||||
|
||||
Future<void> _handleNoteTap(Note note, bool isDesktop) async {
|
||||
@@ -430,7 +428,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
}
|
||||
|
||||
final Note movedNote = visibleNotes[oldIndex];
|
||||
final List<Note> remainingVisible = <Note>[...visibleNotes]..removeAt(oldIndex);
|
||||
final List<Note> remainingVisible = <Note>[...visibleNotes]
|
||||
..removeAt(oldIndex);
|
||||
final int clampedNewIndex = newIndex.clamp(0, remainingVisible.length);
|
||||
|
||||
int targetFullIndex;
|
||||
@@ -442,7 +441,9 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
targetFullIndex = _notes.length - 1;
|
||||
} else {
|
||||
final Note afterNote = remainingVisible[clampedNewIndex];
|
||||
targetFullIndex = _notes.indexWhere((Note note) => note.id == afterNote.id);
|
||||
targetFullIndex = _notes.indexWhere(
|
||||
(Note note) => note.id == afterNote.id,
|
||||
);
|
||||
if (targetFullIndex < 0) {
|
||||
targetFullIndex = 0;
|
||||
}
|
||||
@@ -501,7 +502,10 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Buscar notas...',
|
||||
hintStyle: TextStyle(color: palette.textSecondary),
|
||||
prefixIcon: Icon(Icons.search, color: palette.textSecondary),
|
||||
prefixIcon: Icon(
|
||||
Icons.search,
|
||||
color: palette.textSecondary,
|
||||
),
|
||||
suffixIcon: _searchQuery.isEmpty
|
||||
? null
|
||||
: IconButton(
|
||||
@@ -582,10 +586,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 88),
|
||||
child: Text(
|
||||
_formatLastSyncAt(),
|
||||
style: TextStyle(
|
||||
color: palette.textSecondary,
|
||||
fontSize: 12,
|
||||
),
|
||||
style: TextStyle(color: palette.textSecondary, fontSize: 12),
|
||||
),
|
||||
),
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
@@ -598,6 +599,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
child: NoteCard(
|
||||
note: note,
|
||||
isSelected: note.id == _selectedNoteId,
|
||||
showSelectionBorder: isDesktop,
|
||||
onTap: () => _handleNoteTap(note, isDesktop),
|
||||
onDelete: () => _deleteNote(note),
|
||||
onChangeCategory: (BuildContext buttonContext) =>
|
||||
@@ -637,7 +639,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
final AppPalette palette = _paletteOf(context);
|
||||
final double leftWidth = (constraints.maxWidth * 0.34).clamp(320, 440);
|
||||
final Note? selectedNote = _selectedNote();
|
||||
final bool selectedIsVisible = selectedNote != null &&
|
||||
final bool selectedIsVisible =
|
||||
selectedNote != null &&
|
||||
_visibleNotes().any((Note note) => note.id == selectedNote.id);
|
||||
|
||||
return Row(
|
||||
|
||||
@@ -116,8 +116,8 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
|
||||
RelativeRect _menuRectFromContext(BuildContext anchorContext) {
|
||||
final RenderBox button = anchorContext.findRenderObject()! as RenderBox;
|
||||
final RenderBox overlay = Overlay.of(anchorContext).context.findRenderObject()!
|
||||
as RenderBox;
|
||||
final RenderBox overlay =
|
||||
Overlay.of(anchorContext).context.findRenderObject()! as RenderBox;
|
||||
final Offset topLeft = button.localToGlobal(Offset.zero, ancestor: overlay);
|
||||
final Offset bottomRight = button.localToGlobal(
|
||||
button.size.bottomRight(Offset.zero),
|
||||
@@ -125,12 +125,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
);
|
||||
|
||||
return RelativeRect.fromRect(
|
||||
Rect.fromLTRB(
|
||||
topLeft.dx,
|
||||
topLeft.dy,
|
||||
bottomRight.dx,
|
||||
bottomRight.dy,
|
||||
),
|
||||
Rect.fromLTRB(topLeft.dx, topLeft.dy, bottomRight.dx, bottomRight.dy),
|
||||
Offset.zero & overlay.size,
|
||||
);
|
||||
}
|
||||
@@ -157,7 +152,8 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
isDirty: true,
|
||||
);
|
||||
|
||||
final bool hasChanges = draft.title != _baselineNote.title ||
|
||||
final bool hasChanges =
|
||||
draft.title != _baselineNote.title ||
|
||||
draft.body != _baselineNote.body ||
|
||||
draft.categoryId != _baselineNote.categoryId;
|
||||
|
||||
@@ -206,10 +202,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
for (final Category category in widget.categories)
|
||||
PopupMenuItem<Category?>(
|
||||
value: category,
|
||||
child: Text(category.name),
|
||||
),
|
||||
PopupMenuItem<Category?>(value: category, child: Text(category.name)),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -273,8 +266,11 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEditorBody() {
|
||||
Widget _buildEditorBody({required bool embedded}) {
|
||||
final AppPalette palette = _paletteOf(context);
|
||||
final BoxBorder? bodyBorder = embedded
|
||||
? null
|
||||
: Border.all(color: palette.border);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
@@ -309,7 +305,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
decoration: BoxDecoration(
|
||||
color: palette.transparent,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: palette.border),
|
||||
border: bodyBorder,
|
||||
),
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: QuillEditor.basic(
|
||||
@@ -372,18 +368,16 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
|
||||
final Widget editor = Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: _buildEditorBody(),
|
||||
child: _buildEditorBody(embedded: widget.embedded),
|
||||
);
|
||||
|
||||
if (widget.embedded) {
|
||||
return Container(color: palette.cardBackground, child: editor);
|
||||
return editor;
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: palette.cardBackground,
|
||||
appBar: AppBar(
|
||||
title: const Text('Editar nota'),
|
||||
),
|
||||
appBar: AppBar(title: const Text('Editar nota')),
|
||||
body: SafeArea(child: editor),
|
||||
);
|
||||
}
|
||||
|
||||
+15
-11
@@ -13,6 +13,7 @@ class NoteCard extends StatelessWidget {
|
||||
this.onTap,
|
||||
this.onDelete,
|
||||
this.onChangeCategory,
|
||||
this.showSelectionBorder = true,
|
||||
});
|
||||
|
||||
final Note note;
|
||||
@@ -21,26 +22,32 @@ class NoteCard extends StatelessWidget {
|
||||
final VoidCallback? onTap;
|
||||
final VoidCallback? onDelete;
|
||||
final ValueChanged<BuildContext>? onChangeCategory;
|
||||
final bool showSelectionBorder;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final AppPalette palette = Theme.of(context).extension<AppPalette>()!;
|
||||
final String bodyText = noteBodyToPlainText(note.body).trim();
|
||||
|
||||
return Material(
|
||||
return Material(
|
||||
color: Colors.transparent, // 1. Fondo completamente transparente
|
||||
shape: BorderDirectional(
|
||||
start: BorderSide(
|
||||
color: isSelected ? palette.accent : Colors.transparent,
|
||||
color: (isSelected && showSelectionBorder)
|
||||
? palette.accent
|
||||
: Colors.transparent,
|
||||
width: isSelected ? 1.6 : 1.0,
|
||||
),
|
||||
),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
onTap: onTap,
|
||||
hoverColor: Colors.transparent, // 2. Desactiva el efecto hover (pasar el ratón)
|
||||
splashColor: Colors.transparent, // 3. Desactiva el efecto de onda al hacer clic
|
||||
highlightColor: Colors.transparent, // Desactiva el brillo al mantener pulsado
|
||||
hoverColor:
|
||||
Colors.transparent, // 2. Desactiva el efecto hover (pasar el ratón)
|
||||
splashColor:
|
||||
Colors.transparent, // 3. Desactiva el efecto de onda al hacer clic
|
||||
highlightColor:
|
||||
Colors.transparent, // Desactiva el brillo al mantener pulsado
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
child: Row(
|
||||
@@ -78,10 +85,7 @@ return Material(
|
||||
const SizedBox(width: 8),
|
||||
PopupMenuButton<String>(
|
||||
tooltip: 'Más opciones',
|
||||
icon: Icon(
|
||||
Icons.more_vert,
|
||||
color: palette.textSecondary,
|
||||
),
|
||||
icon: Icon(Icons.more_vert, color: palette.textSecondary),
|
||||
onOpened: () {},
|
||||
onSelected: (String value) {
|
||||
switch (value) {
|
||||
@@ -108,6 +112,6 @@ return Material(
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user