mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-11 12:47:46 +01:00
Editing an existing note looked nothing like capturing a new one: it always showed the template dropdown, the View/Guided/Raw pills and the priority/status row. The cause was one missing argument -- both screens already embedded the same NoteEditor, but NoteDetailScreen never passed advancedMode, which defaults to true in the widget while the app-wide AppSettings.advancedMode defaults to false. Extract the shared form as three single-purpose components rather than one widget owning several jobs: - note_meta_row.dart renders the priority/status row (was capture_meta_row.dart; drops the private _MetaDropdown duplicate the detail screen carried, which used DropdownButtonFormField where the shared one uses DropdownButton). - note_form_chrome_gate.dart owns chrome visibility and nothing else, replacing the _chromeVisible flag both screens copy-pasted. - note_form.dart composes those two with NoteEditor. appSettings is now a required parameter through NotesListScreen and NoteDetailScreen. Required, not defaulted: a silent default is exactly what caused this, so it must not be reintroducible. Also in the capture app bar: drop the decorative Icons.list_alt_outlined beside the note count, since the adjacent Icons.list button already names what is counted, and move the count to the right of that button. The finalize-and-clear action becomes Icons.check instead of Icons.add -- it never saved anything (every keystroke is already persisted), so a plus sign misdescribed it. 314 tests, 100% line coverage. Verified in a running web build that edit and capture render identically with advanced mode both off and on. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
115 lines
3.4 KiB
Dart
115 lines
3.4 KiB
Dart
/// The capture screen's app bar: note count, and the four actions.
|
|
///
|
|
/// Split out of `capture_screen.dart` for file size. Callback-only — the
|
|
/// screen still owns every action; this just lays the row out.
|
|
library;
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:todo/data/note_repository.dart';
|
|
import 'package:todo/frame_stats.dart';
|
|
|
|
/// App bar for the capture screen.
|
|
class CaptureAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|
/// Creates the capture screen's app bar.
|
|
const CaptureAppBar({
|
|
required this.repository,
|
|
required this.advanced,
|
|
required this.syncing,
|
|
required this.onNewNote,
|
|
required this.onSync,
|
|
required this.onOpenList,
|
|
required this.onOpenSettings,
|
|
super.key,
|
|
});
|
|
|
|
/// Store whose note count is shown live.
|
|
final NoteRepository repository;
|
|
|
|
/// Whether advanced mode is on; hides the manual Sync action when off.
|
|
final bool advanced;
|
|
|
|
/// Whether a sync is in flight, which disables and spins the Sync action.
|
|
final bool syncing;
|
|
|
|
/// Saves the current draft and clears the box for a new one.
|
|
final VoidCallback onNewNote;
|
|
|
|
/// Runs a manual sync.
|
|
final VoidCallback onSync;
|
|
|
|
/// Opens the notes list.
|
|
final VoidCallback onOpenList;
|
|
|
|
/// Opens the settings screen.
|
|
final VoidCallback onOpenSettings;
|
|
|
|
@override
|
|
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AppBar(
|
|
actions: [
|
|
// TEMPORARY: forces continuous frame production so raster cost
|
|
// can be sampled at each window size. Armed by
|
|
// TODO_FRAME_STATS=1, which is never set under the test
|
|
// runner, so the branch is unreachable.
|
|
// coverage:ignore-start
|
|
if (frameStatsEnabled)
|
|
const Padding(
|
|
padding: EdgeInsets.only(right: 8),
|
|
child: Center(
|
|
child: SizedBox(
|
|
width: 18,
|
|
height: 18,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
),
|
|
),
|
|
),
|
|
// coverage:ignore-end
|
|
IconButton(
|
|
tooltip: 'New note',
|
|
onPressed: onNewNote,
|
|
icon: const Icon(Icons.check),
|
|
),
|
|
if (advanced)
|
|
IconButton(
|
|
tooltip: 'Sync',
|
|
onPressed: syncing ? null : onSync,
|
|
icon: syncing
|
|
? const SizedBox(
|
|
width: 18,
|
|
height: 18,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: const Icon(Icons.sync),
|
|
),
|
|
IconButton(
|
|
tooltip: 'Notes',
|
|
onPressed: onOpenList,
|
|
icon: const Icon(Icons.list),
|
|
),
|
|
// Live count of stored notes, proving local persistence. Sits directly
|
|
// right of the Notes button it belongs to, and carries no icon of its
|
|
// own -- that button's Icons.list already names what is being counted.
|
|
StreamBuilder<int>(
|
|
stream: repository.watchCount(),
|
|
builder: (context, snapshot) {
|
|
final count = snapshot.data ?? 0;
|
|
return Padding(
|
|
padding: const EdgeInsets.only(right: 4),
|
|
child: Center(child: Text('$count')),
|
|
);
|
|
},
|
|
),
|
|
IconButton(
|
|
tooltip: 'Settings',
|
|
onPressed: onOpenSettings,
|
|
icon: const Icon(Icons.settings),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|