todo-app/lib/ui/images/image_strip.dart
Krzysztof kuhy Rudnicki 0798f7b1d0 Attach images to notes, stored on dufs and kept offline
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-25 14:11:15 +02:00

49 lines
1.7 KiB
Dart

import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:todo/images/image_ref.dart';
import 'package:todo/ui/images/image_embed.dart';
/// Height of the thumbnail row under the editor.
const kImageStripHeight = 88.0;
/// A row of thumbnails for every image [text] links to, shown under the
/// editing field so a note's pictures are visible while writing it. The
/// editing modes show the links as text; without this the default (Raw)
/// mode would never show an image at all. Empty when there are none.
class ImageStrip extends StatelessWidget {
/// Creates the strip for [text].
const ImageStrip({required this.text, super.key});
/// The note text being edited.
final String text;
@override
Widget build(BuildContext context) {
final refs = imageRefsIn(text).toList();
if (refs.isEmpty) return const SizedBox.shrink();
// Same centred column as the editor above it (rule 21), so on the wide
// desktop window the thumbnails sit under the text, not at the far edge.
return Padding(
padding: const EdgeInsets.only(top: 8),
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: kProseMaxWidth,
maxHeight: kImageStripHeight,
),
child: ListView.separated(
scrollDirection: Axis.horizontal,
itemCount: refs.length,
separatorBuilder: (_, _) => const SizedBox(width: 8),
itemBuilder: (context, i) => SizedBox(
width: kImageStripHeight,
child: ImageEmbed(ref: refs[i]),
),
),
),
),
);
}
}