Files
pipelines/app/lib/features/chat/ui/transcript/chat_image_viewer.dart
T
alan fde086cc4a feat(app): glass viewer bars, graph controls and immersive image viewer
Review findings F12, F13, F25 and F1 for viewers: the artifact viewer's
actions/pager and the Changes pager float as glass pills over content,
file facts move to the top bar, graph overlay controls are one glass pill
(duplicate fullscreen glyph removed), the image viewer is immersive, and
diff/artifact/graph views let content pass behind the bar. Implemented by
pipeline run #204 (Terra); its Review stopped after three rejections, the
last being an empty glass bar for a single unresolved artifact, which the
manager fixed here with a regression test.
2026-10-31 04:26:22 +00:00

101 lines
3.0 KiB
Dart

import '../../../../ui/adaptive/segmented_bar.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 = 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(
backgroundColor: CupertinoColors.black,
navigationBar: SegmentedBar(
cupertino: true,
automaticallyImplyLeading: false,
title: name,
backgroundColor: CupertinoColors.black,
pillColor: CupertinoColors.darkBackgroundGray,
foregroundColor: CupertinoColors.white,
leading: CupertinoButton(
key: const Key('chat-image-viewer-close'),
padding: const EdgeInsets.symmetric(horizontal: 16),
onPressed: close,
child: const Text(chatImageViewerClose),
),
),
child: body,
);
}
return Scaffold(
extendBodyBehindAppBar: true,
backgroundColor: Colors.black,
appBar: SegmentedBar(
cupertino: false,
automaticallyImplyLeading: false,
leading: IconButton(
key: const Key('chat-image-viewer-close'),
tooltip: chatImageViewerClose,
onPressed: close,
icon: const Icon(Icons.close),
),
title: name,
backgroundColor: Colors.black,
pillColor: Colors.white24,
foregroundColor: Colors.white,
),
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);
}