Files
pipelines/app/lib/features/chat/ui/transcript/chat_image_viewer.dart
T
alan 0582bfc34f feat(app): segmented glass top bar across the app
Extract the chat's segmented bar into lib/ui/adaptive (SegmentedBar,
GlassPill, SegmentedBarOverlay) and use it for the shell bar, DetailPane
and every page-level bar. Pieces are frosted glass over a fading scrim;
only pills take taps. Actions keep their natural width so the title gives
way before a model name. The chat transcript scrolls behind its header.
2026-10-31 00:21:27 +00:00

95 lines
2.8 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 = 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: SegmentedBar(
cupertino: true,
automaticallyImplyLeading: false,
title: name,
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,
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,
),
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);
}