4e0481fd8d
Full screen button in the viewer's bottom bar opens a root full-screen route with the same bar and top bar; exit by the bar, Close, Escape or back. It renders the already fetched bytes, never the system browser. The external Open action is now labelled Open in browser. Native web views claim their gestures (vertical drags inline, every pointer in full screen) so the page swipe no longer starves them. On the web, full screen adds zoom buttons that scale the live sandboxed frame. Links: in-page anchors scroll, http(s)/mailto open outside, everything else is inert. Capture kit: --touch, swipe=, pinch=, tabs=; html=1 fixture artifact.
198 lines
5.9 KiB
Dart
198 lines
5.9 KiB
Dart
import 'dart:typed_data';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/host.dart';
|
|
import '../../../ui/adaptive/floating_bar_layout.dart';
|
|
import '../actions/artifact_file_actions.dart';
|
|
import '../actions/artifact_file_bridge.dart';
|
|
import '../domain/artifact_preview.dart';
|
|
import '../domain/gallery_navigation.dart';
|
|
import 'artifact_html_view.dart';
|
|
import 'artifact_viewer_bar.dart';
|
|
import 'artifact_viewer_content.dart';
|
|
import 'artifact_viewer_fetch.dart';
|
|
|
|
export 'artifact_controls_overlay.dart';
|
|
export 'artifact_viewer_bar.dart'
|
|
show artifactFullscreenKey, artifactNextKey, artifactPreviousKey;
|
|
|
|
/// One viewer page: the recorded facts, position, live status, preview surface,
|
|
/// file transfer actions, external actions and paging controls.
|
|
///
|
|
/// It is stateless so the page owns loading, fetch generations and focus; this
|
|
/// surface only draws the current page and reports the operator's intent. The
|
|
/// page content scrolls as one column at large text sizes; paging stays fixed.
|
|
class ArtifactViewerBody extends StatelessWidget {
|
|
const ArtifactViewerBody({
|
|
super.key,
|
|
required this.page,
|
|
required this.plan,
|
|
required this.index,
|
|
required this.count,
|
|
required this.loading,
|
|
required this.markdownBuilder,
|
|
required this.onPrevious,
|
|
required this.onNext,
|
|
required this.onOpen,
|
|
required this.onCopy,
|
|
this.fetch = fetchArtifact,
|
|
this.fileBridge = const ArtifactFileBridge(),
|
|
this.text,
|
|
this.bytes,
|
|
this.error,
|
|
this.status,
|
|
this.onRetry,
|
|
this.htmlBuilder = defaultArtifactHtml,
|
|
this.fullscreen = false,
|
|
this.onFullscreen,
|
|
});
|
|
|
|
/// The inert HTML renderer; tests inject a plain stand-in.
|
|
final ArtifactHtmlBuilder htmlBuilder;
|
|
|
|
/// Whether this body is the full-screen view's ([ArtifactViewerBar]).
|
|
final bool fullscreen;
|
|
|
|
/// Enters or leaves the full-screen view.
|
|
final VoidCallback? onFullscreen;
|
|
|
|
/// Loads the current page's preview again after a failure.
|
|
final VoidCallback? onRetry;
|
|
|
|
final PagedArtifact page;
|
|
final ArtifactPreviewPlan plan;
|
|
final int index;
|
|
final int count;
|
|
final bool loading;
|
|
final ArtifactMarkdownBuilder markdownBuilder;
|
|
final VoidCallback onPrevious;
|
|
final VoidCallback onNext;
|
|
final VoidCallback onOpen;
|
|
final VoidCallback onCopy;
|
|
final ArtifactFetch fetch;
|
|
final ArtifactFileBridge fileBridge;
|
|
final String? text;
|
|
final Uint8List? bytes;
|
|
final String? error;
|
|
final String? status;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final resolved = plan.resolved;
|
|
final preview = Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Expanded(
|
|
child: ArtifactPreviewBody(
|
|
plan: plan,
|
|
loading: loading,
|
|
markdownBuilder: markdownBuilder,
|
|
text: text,
|
|
bytes: bytes,
|
|
error: error,
|
|
onRetry: onRetry,
|
|
htmlBuilder: htmlBuilder,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
// The page never scrolls: the preview fills the space between the top
|
|
// bar and the bottom controls (it zooms or scrolls itself), never
|
|
// passing behind either; the insets are spent here, not again inside.
|
|
final content = Builder(
|
|
builder: (context) {
|
|
final insets = MediaQuery.paddingOf(context);
|
|
return Padding(
|
|
padding: EdgeInsets.only(top: insets.top, bottom: insets.bottom),
|
|
child: MediaQuery.removePadding(
|
|
context: context,
|
|
removeTop: true,
|
|
removeBottom: true,
|
|
child: preview,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
final hasPrevious = pagedIndex(index, -1, count) != index;
|
|
final hasNext = pagedIndex(index, 1, count) != index;
|
|
final swipe = GestureDetector(
|
|
key: const Key('artifact-viewer-swipe'),
|
|
behavior: HitTestBehavior.translucent,
|
|
onHorizontalDragEnd: (details) {
|
|
final velocity = details.primaryVelocity ?? 0;
|
|
if (velocity < -250 && hasNext) onNext();
|
|
if (velocity > 250 && hasPrevious) onPrevious();
|
|
},
|
|
child: content,
|
|
);
|
|
// An unresolved single artifact has no actions and nothing to page:
|
|
// no empty glass bar, and no bottom clearance reserved for one.
|
|
if (resolved == null && count <= 1) return swipe;
|
|
return FloatingBarOverlay(
|
|
bar: ArtifactViewerBar(
|
|
page: page,
|
|
resolved: resolved,
|
|
index: index,
|
|
count: count,
|
|
fetch: fetch,
|
|
fileBridge: fileBridge,
|
|
onOpen: onOpen,
|
|
onCopy: onCopy,
|
|
onPrevious: onPrevious,
|
|
onNext: onNext,
|
|
fullscreen: fullscreen,
|
|
onFullscreen: onFullscreen,
|
|
),
|
|
child: swipe,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The viewer's top edge: where this artifact sits in the list, and an
|
|
/// information button for its recorded facts.
|
|
class ArtifactViewerInfoAction extends StatelessWidget {
|
|
const ArtifactViewerInfoAction({super.key, required this.facts});
|
|
|
|
final Widget facts;
|
|
|
|
void _show(BuildContext context) {
|
|
if (usesCupertinoHost(context)) {
|
|
showCupertinoModalPopup<void>(
|
|
context: context,
|
|
builder: (context) => CupertinoPopupSurface(
|
|
child: SafeArea(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: facts,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
showModalBottomSheet<void>(
|
|
context: context,
|
|
showDragHandle: true,
|
|
builder: (context) => SafeArea(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
|
child: facts,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ArtifactIconAction(
|
|
key: const Key('artifact-info'),
|
|
label: 'Details',
|
|
icon: Icons.info_outline,
|
|
cupertinoIcon: CupertinoIcons.info,
|
|
onPressed: () => _show(context),
|
|
);
|
|
}
|
|
}
|