Files
pipelines/app/lib/features/chat/ui/transcript/chat_image_viewer.dart
T
alan 8c421952db feat(chat): show sent images as thumbnails with a full-screen viewer
Operator-attached images render as rounded thumbnails above the user
bubble and open a zoomable Material/Cupertino viewer. Inline data: URIs
decode locally; file:// attachment-store URIs load through the new
chat_attachment_image websocket request, which serves only regular image
files directly inside the private attachment store (os.Root, <= 4 MiB,
sniffed raster types). Missing files show an 'Image no longer available'
placeholder; other files keep the file row.
2026-10-30 20:53:03 +00:00

91 lines
2.7 KiB
Dart

import 'dart:typed_data';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// The accessible name and visible label of the viewer's close control.
const String chatImageViewerClose = 'Close';
/// One attached image full screen: pinch or scroll to zoom, drag to pan once
/// zoomed, and the host's own close control in the navigation bar.
class ChatImageViewer extends StatelessWidget {
const ChatImageViewer({
super.key,
required this.name,
required this.bytes,
required this.cupertino,
});
final String name;
final Uint8List bytes;
final bool cupertino;
@override
Widget build(BuildContext context) {
final body = SafeArea(
child: InteractiveViewer(
key: const Key('chat-image-viewer-zoom'),
maxScale: 8,
child: Center(
child: Semantics(
image: true,
label: name,
child: Image.memory(
bytes,
key: const Key('chat-image-viewer-image'),
fit: BoxFit.contain,
gaplessPlayback: true,
errorBuilder: (context, _, _) => Icon(
cupertino ? CupertinoIcons.photo : Icons.broken_image_outlined,
),
),
),
),
),
);
void close() => Navigator.of(context).maybePop();
if (cupertino) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
automaticallyImplyLeading: false,
middle: Text(name, overflow: TextOverflow.ellipsis),
leading: CupertinoButton(
key: const Key('chat-image-viewer-close'),
padding: EdgeInsets.zero,
onPressed: close,
child: const Text(chatImageViewerClose),
),
),
child: body,
);
}
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
leading: IconButton(
key: const Key('chat-image-viewer-close'),
tooltip: chatImageViewerClose,
onPressed: close,
icon: const Icon(Icons.close),
),
title: Text(name, overflow: TextOverflow.ellipsis),
),
body: body,
);
}
}
/// Pushes [ChatImageViewer] with the host's full-screen dialog transition.
Future<void> openChatImageViewer(
BuildContext context, {
required String name,
required Uint8List bytes,
required bool cupertino,
}) {
final page = ChatImageViewer(name: name, bytes: bytes, cupertino: cupertino);
final route = cupertino
? CupertinoPageRoute<void>(fullscreenDialog: true, builder: (_) => page)
: MaterialPageRoute<void>(fullscreenDialog: true, builder: (_) => page);
return Navigator.of(context).push(route);
}