mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-20 06:54:25 +01:00
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
repo-contract / repo contract (push) Has been cancelled
crdt_sync_flutter 0.9.0's installAppErrors in main(): uncaught errors and every spinner shown over 1 s (WaitWatch: sync.run, mirror.test) upload to RTDB /todo/errors/<device> with the versionCode, where the PC app-errors ingest files board tickets (kuhyx/utils DOCS-app-errors.md). The app moves to material_ui first: sync_settings_ui 0.8.x and design_system 0.4.x sit on it, and Flutter 3.50 deprecates flutter/material. Pins: crdt_sync 0.14.1, csf 0.9.0, ssui 0.8.3, gda 0.5.1, design_system 0.4.1, image 4.13.1, mcp_dart 2.4.4. file_picker stays 13.3.3, held by data_transfer_flutter 0.2.2 (allowlisted, self-clearing). appRoute takes a route name so each report names its screen; the release build passes APP_BUILD/APP_VERSION. Nothing new on screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
118 lines
3.6 KiB
Dart
118 lines
3.6 KiB
Dart
/// One attached image as it appears in a note: the picture, or a placeholder
|
|
/// saying why it is not here yet. Tapping opens it full screen.
|
|
library;
|
|
|
|
import 'package:material_ui/material_ui.dart';
|
|
|
|
import 'package:todo/attachments/image_store_api.dart';
|
|
import 'package:todo/attachments/image_store_scope.dart';
|
|
import 'package:todo/images/attachment_ref.dart';
|
|
import 'package:todo/ui/app_route.dart';
|
|
import 'package:todo/ui/images/image_viewer_screen.dart';
|
|
import 'package:todo/ui/images/local_image.dart';
|
|
|
|
/// Placeholder text for an image this device does not have yet.
|
|
const kImageNotDownloaded = 'Not downloaded yet';
|
|
|
|
/// Tooltip on the badge of an image dufs has not accepted yet.
|
|
const kImageWaitingToUpload = 'Waiting to upload';
|
|
|
|
/// Renders [ref] from the nearest [ImageStoreScope].
|
|
class ImageEmbed extends StatelessWidget {
|
|
/// Creates an embed; [fit] is `cover` for thumbnails, `contain` inline.
|
|
const ImageEmbed({required this.ref, this.fit = BoxFit.cover, super.key});
|
|
|
|
/// The image to show.
|
|
final AttachmentRef ref;
|
|
|
|
/// How the picture fills the embed's box.
|
|
final BoxFit fit;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final store = ImageStoreScope.of(context);
|
|
final source = store.sourceFor(ref);
|
|
final picture = imageFor(source, fit: fit);
|
|
// Spoken only: nothing paints this string.
|
|
const semanticLabel = 'Attached image';
|
|
return Semantics(
|
|
label: semanticLabel,
|
|
button: source is! MissingImageSource,
|
|
child: GestureDetector(
|
|
onTap: source is MissingImageSource
|
|
? null
|
|
: () => Navigator.of(context).push<void>(
|
|
appRoute(
|
|
context,
|
|
(_) => ImageViewerScreen(source: source),
|
|
name: '/image',
|
|
),
|
|
),
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(8),
|
|
child: Stack(
|
|
fit: StackFit.passthrough,
|
|
children: [
|
|
picture,
|
|
if (store.isPending(ref))
|
|
const Positioned(
|
|
right: 4,
|
|
top: 4,
|
|
child: Icon(
|
|
Icons.cloud_upload_outlined,
|
|
size: 18,
|
|
semanticLabel: kImageWaitingToUpload,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The picture for [source], falling back to the not-downloaded placeholder
|
|
/// (also when a network load fails: the wrapper 404s until it has the file).
|
|
Widget imageFor(ImageSource source, {required BoxFit fit}) {
|
|
Widget placeholder(BuildContext context, Object error, StackTrace? stack) =>
|
|
const ImagePlaceholder();
|
|
return switch (source) {
|
|
LocalImageSource(:final path) => localImage(
|
|
path,
|
|
fit: fit,
|
|
errorBuilder: placeholder,
|
|
),
|
|
NetworkImageSource(:final url) => Image.network(
|
|
url,
|
|
fit: fit,
|
|
errorBuilder: placeholder,
|
|
),
|
|
MissingImageSource() => const ImagePlaceholder(),
|
|
};
|
|
}
|
|
|
|
/// Grey box with a download glyph, spoken as [kImageNotDownloaded].
|
|
class ImagePlaceholder extends StatelessWidget {
|
|
/// Creates the placeholder.
|
|
const ImagePlaceholder({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
return ColoredBox(
|
|
color: theme.colorScheme.surfaceContainerHighest,
|
|
child: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: Icon(
|
|
Icons.cloud_download_outlined,
|
|
color: theme.colorScheme.outline,
|
|
semanticLabel: kImageNotDownloaded,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|