mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-10 18:07:03 +01:00
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
49 lines
1.4 KiB
Dart
49 lines
1.4 KiB
Dart
/// The notes list's body: phone grid or desktop list of notes.
|
|
///
|
|
/// Split out of `notes_list_screen.dart` for file size.
|
|
library;
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:todo/data/note.dart';
|
|
import 'package:todo/ui/note_tile.dart';
|
|
import 'package:todo/ui/notes_grid.dart';
|
|
|
|
/// Lays [notes] out as a grid below [kNotesGridMaxWidth], else a list.
|
|
class NotesListBody extends StatelessWidget {
|
|
/// Creates the body; callbacks get the tapped note.
|
|
const NotesListBody({
|
|
required this.notes,
|
|
required this.onOpen,
|
|
required this.onActions,
|
|
super.key,
|
|
});
|
|
|
|
/// Notes in display order.
|
|
final List<Note> notes;
|
|
|
|
/// Tap on a note.
|
|
final ValueChanged<Note> onOpen;
|
|
|
|
/// Long-press (or the actions button) on a note.
|
|
final ValueChanged<Note> onActions;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return LayoutBuilder(
|
|
builder: (context, box) => box.maxWidth < kNotesGridMaxWidth
|
|
? NotesGrid(notes: notes, onOpen: onOpen, onActions: onActions)
|
|
: ListView.separated(
|
|
itemCount: notes.length,
|
|
separatorBuilder: (_, _) => const Divider(height: 1),
|
|
itemBuilder: (context, i) => NoteTile(
|
|
key: ValueKey(notes[i].id),
|
|
note: notes[i],
|
|
onTap: () => onOpen(notes[i]),
|
|
onActions: () => onActions(notes[i]),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|