Files
pipelines/app/lib/features/artifacts/ui/artifact_fullscreen.dart
T
alan 8e5a88beff Remove alternate feature icon metadata
Preserve reviewed Material-only feature changes after the pipeline's landing stage incorrectly refused shell committing. Keep required shared compatibility inputs until the coordinated caller cleanup.
2026-11-11 20:03:57 +00:00

108 lines
3.6 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/segmented_bar_overflow.dart';
import '../actions/artifact_file_actions.dart';
/// Marks a subtree as the artifact viewer's full-screen view, where an HTML
/// document takes every gesture over it (scroll, pan, pinch) instead of
/// sharing them with the viewer's page swipe, and follows [htmlZoom].
class ArtifactFullscreenScope extends InheritedWidget {
const ArtifactFullscreenScope({
super.key,
required this.htmlZoom,
required super.child,
});
/// The HTML document's zoom factor (1 is the document's own size), set by
/// [ArtifactHtmlZoomActions].
final ValueListenable<double> htmlZoom;
static ArtifactFullscreenScope? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<ArtifactFullscreenScope>();
@override
bool updateShouldNotify(ArtifactFullscreenScope oldWidget) =>
htmlZoom != oldWidget.htmlZoom;
}
/// The full-screen view's route, pushed on the root navigator so it covers
/// the shell's bars and list pane. A full-screen dialog route: its bar shows
/// the platform's Close, and the system back gesture leaves it.
///
/// [cupertino] is retained for callers that still pass it; the route is always
/// the Material one.
Route<void> artifactFullscreenRoute({
bool? cupertino,
required WidgetBuilder builder,
}) => MaterialPageRoute<void>(fullscreenDialog: true, builder: builder);
/// The zoom factors Zoom in and Zoom out step through.
const List<double> artifactHtmlZoomSteps = [
0.5, 0.67, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, //
];
/// The next zoom step from [current] in [direction] (+1 in, -1 out), held at
/// both ends.
double artifactHtmlZoomStep(double current, int direction) {
if (direction > 0) {
return artifactHtmlZoomSteps.firstWhere(
(step) => step > current + 0.001,
orElse: () => artifactHtmlZoomSteps.last,
);
}
return artifactHtmlZoomSteps.lastWhere(
(step) => step < current - 0.001,
orElse: () => artifactHtmlZoomSteps.first,
);
}
const artifactZoomOutKey = ValueKey<String>('artifact-zoom-out');
const artifactZoomResetKey = ValueKey<String>('artifact-zoom-reset');
const artifactZoomInKey = ValueKey<String>('artifact-zoom-in');
/// Zoom out, actual size and zoom in for an HTML document, as top-bar
/// actions (a narrow bar moves them into its More menu). Used where the
/// document cannot be pinched (the web's sandboxed frame): the frame keeps
/// scrolling the live document at the chosen size.
List<Widget> artifactHtmlZoomActions(ValueNotifier<double> zoom) {
void step(int direction) =>
zoom.value = artifactHtmlZoomStep(zoom.value, direction);
final percent = '${(zoom.value * 100).round()}%';
Widget action(
Key key,
String label,
IconData icon,
VoidCallback? onPressed,
) => SegmentedOverflowAction(
key: key,
overflowEntry: SegmentedOverflowEntry(
label: label,
icon: icon,
onPressed: onPressed,
),
child: ArtifactIconAction(label: label, icon: icon, onPressed: onPressed),
);
final value = zoom.value;
return [
action(
artifactZoomOutKey,
'Zoom out',
Icons.zoom_out,
value > artifactHtmlZoomSteps.first + 0.001 ? () => step(-1) : null,
),
action(
artifactZoomResetKey,
'Actual size ($percent)',
Icons.restart_alt,
(value - 1).abs() > 0.001 ? () => zoom.value = 1 : null,
),
action(
artifactZoomInKey,
'Zoom in',
Icons.zoom_in,
value < artifactHtmlZoomSteps.last - 0.001 ? () => step(1) : null,
),
];
}