8e5a88beff
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.
151 lines
5.1 KiB
Dart
151 lines
5.1 KiB
Dart
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/glass_bar.dart';
|
|
import '../../../ui/navigation/chevron_pager.dart';
|
|
import '../actions/artifact_file_actions.dart';
|
|
import '../actions/artifact_file_bridge.dart';
|
|
import '../domain/artifact_url.dart';
|
|
import '../domain/gallery_navigation.dart';
|
|
import 'artifact_viewer_fetch.dart';
|
|
|
|
const artifactPreviousKey = ValueKey<String>('artifact-previous');
|
|
const artifactNextKey = ValueKey<String>('artifact-next');
|
|
const artifactFullscreenKey = ValueKey<String>('artifact-fullscreen');
|
|
|
|
/// The viewer's bottom controls: file transfer, Open, Copy link, Full screen
|
|
/// and the pager, in one glass bar above the bottom safe area.
|
|
///
|
|
/// The inline viewer and the full-screen view draw this same bar; in full
|
|
/// screen the Full screen control reads Exit full screen and leaves it.
|
|
class ArtifactViewerBar extends StatelessWidget {
|
|
const ArtifactViewerBar({
|
|
super.key,
|
|
required this.page,
|
|
required this.resolved,
|
|
required this.index,
|
|
required this.count,
|
|
required this.fetch,
|
|
required this.fileBridge,
|
|
this.downloadResolved,
|
|
required this.onOpen,
|
|
required this.onCopy,
|
|
required this.onPrevious,
|
|
required this.onNext,
|
|
this.fullscreen = false,
|
|
this.onFullscreen,
|
|
});
|
|
|
|
final PagedArtifact page;
|
|
final ResolvedArtifactUrl? resolved;
|
|
final int index;
|
|
final int count;
|
|
final ArtifactFetch fetch;
|
|
final ArtifactFileBridge fileBridge;
|
|
final ResolvedArtifactUrl? downloadResolved;
|
|
final VoidCallback onOpen;
|
|
final VoidCallback onCopy;
|
|
final VoidCallback onPrevious;
|
|
final VoidCallback onNext;
|
|
|
|
/// Whether this bar is the full-screen view's.
|
|
final bool fullscreen;
|
|
|
|
/// Enters (inline) or leaves (in full screen) the full-screen view; absent,
|
|
/// the control is not drawn.
|
|
final VoidCallback? onFullscreen;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final actions = _actions(resolved, onFullscreen);
|
|
final pagerMin = count > 1 ? 2 * GlassBarMetrics.controlExtent(false) : 0.0;
|
|
final pager = ChevronPager(
|
|
index: index,
|
|
count: count,
|
|
previousLabel: 'Previous artifact',
|
|
nextLabel: 'Next artifact',
|
|
previousKey: artifactPreviousKey,
|
|
nextKey: artifactNextKey,
|
|
onPrevious: pagedIndex(index, -1, count) != index ? onPrevious : null,
|
|
onNext: pagedIndex(index, 1, count) != index ? onNext : null,
|
|
);
|
|
return SafeArea(
|
|
// The SafeArea already lifts the bar by the inherited bottom inset (a
|
|
// shell bar below the pane); adding that clearance again floated the
|
|
// bar far above it.
|
|
top: false,
|
|
minimum: const EdgeInsets.all(8),
|
|
// Without a pager the bar is as wide as its actions, so its last
|
|
// control keeps the same gap from the bar's end as the first.
|
|
child: Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
heightFactor: 1,
|
|
child: GlassControlBar(
|
|
cupertino: false,
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) => Row(
|
|
key: const Key('artifact-viewer-actions'),
|
|
mainAxisSize: count > 1 ? MainAxisSize.max : MainAxisSize.min,
|
|
children: [
|
|
// On a narrow window or at large text the actions scroll
|
|
// sideways, so the chevrons beside them stay whole.
|
|
ConstrainedBox(
|
|
constraints: BoxConstraints(
|
|
maxWidth: math.max(0, constraints.maxWidth - pagerMin),
|
|
),
|
|
child: SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: actions,
|
|
),
|
|
),
|
|
),
|
|
if (count > 1) Expanded(child: pager),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
List<Widget> _actions(ResolvedArtifactUrl? resolved, VoidCallback? toggle) =>
|
|
[
|
|
if (resolved != null && !resolved.external)
|
|
ArtifactFileActions(
|
|
key: ValueKey<String>(
|
|
'viewer-files-${page.group.stageKey}\u0000'
|
|
'${page.group.visit}\u0000${page.artifact.url}',
|
|
),
|
|
artifact: page.artifact,
|
|
resolved: downloadResolved ?? resolved,
|
|
fetch: fetch,
|
|
bridge: fileBridge,
|
|
compact: true,
|
|
),
|
|
if (resolved != null) ...[
|
|
ArtifactIconAction(
|
|
key: const Key('artifact-open'),
|
|
label: 'Open in browser',
|
|
icon: Icons.open_in_new,
|
|
onPressed: onOpen,
|
|
),
|
|
ArtifactIconAction(
|
|
key: const Key('artifact-copy-link'),
|
|
label: 'Copy link',
|
|
icon: Icons.link,
|
|
onPressed: onCopy,
|
|
),
|
|
],
|
|
if (toggle != null)
|
|
ArtifactIconAction(
|
|
key: artifactFullscreenKey,
|
|
label: fullscreen ? 'Exit full screen' : 'Full screen',
|
|
icon: fullscreen ? Icons.fullscreen_exit : Icons.fullscreen,
|
|
onPressed: toggle,
|
|
),
|
|
];
|
|
}
|