todo-app/lib/ui/capture_app_bar.dart
Krzysztof kuhy Rudnicki 9f2ffdb8a9
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
file-length / file length <= 250 lines (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
release-apk / release (APK) (push) Has been cancelled
Attach any file to a note, of any size, not only images
📎 now picks any file (Android: Camera / Gallery / File; desktop: an
unfiltered dialog) and the desktop page accepts any dropped file. Photo and
screenshot formats up to 64 MB are still re-encoded and shown inline;
everything else is stored byte for byte on dufs beside the images and linked
as [name](url), shown as a row with its size that opens in the platform's
app (Android) or a new browser tab (desktop). BACKLOG.md rewrites file links
to ~/data/cloud/todo-images/ like image links.

There is no size cap, so no layer holds a file in memory: uploads and
downloads stream through DufsImageClient, writes land in a .tmp renamed when
whole (an interrupted download no longer leaves a truncated file that looks
done), the desktop page POSTs the browser's own Blob with fetch, and Android's
"File" uses file_picker, because file_selector's Android side reads the whole
file into memory on the UI thread. Verified with a 1 GB file end to end on
desktop (peak RSS +36 MB) and on an API 36 emulator.

The wrapper serves attachments from the origin that holds the GitHub token
and the notes, so only script-free types open inline (nosniff), the rest
download; writes carrying another site's Origin are refused (this also
closes cross-site overwrites of the backup files); and attachment routes run
concurrently so a long upload or a playing video cannot stall the page.

Also: cupertino_icons 2.0.0 (unused, but the freshness gate blocks the
pubspec otherwise), open_file 4.0.0 and file_picker 13.1.0 pinned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 12:17:06 +02:00

126 lines
3.9 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';
import 'package:todo/ui/attachment_picking.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,
required this.onAttachFiles,
this.attachmentPicking,
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;
/// Receives files picked with the 📎 action.
final ValueChanged<List<XFile>> onAttachFiles;
/// The picker behind 📎; null uses the platform one.
final AttachmentPicking? attachmentPicking;
@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
// Not gated on advanced mode: attaching is basic capture.
AttachButton(onFiles: onAttachFiles, picking: attachmentPicking),
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),
),
],
);
}
}