9551eceaed
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
190 lines
6.3 KiB
Dart
190 lines
6.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/glass_pill.dart';
|
|
import 'graph_viewport_controller.dart';
|
|
|
|
/// The fit control's web wording (`Fit graph to view`).
|
|
const String graphFitLabel = 'Fit graph to view';
|
|
|
|
/// The expand control's web wording (`Expand graph`).
|
|
const String graphExpandLabel = 'Expand graph';
|
|
|
|
/// A bounded graph canvas with the host's own pan, pinch, wheel and trackpad
|
|
/// zoom, plus a fit control and an optional expanded presentation.
|
|
///
|
|
/// [controller] owns the transform, so a caller can read or restore a
|
|
/// [GraphViewportSnapshot]. Gestures are consumed only inside this widget's
|
|
/// box: an ancestor scroll view keeps scrolling everywhere else, and a tap
|
|
/// that does not move still reaches the native node under the pointer.
|
|
class GraphViewport extends StatefulWidget {
|
|
const GraphViewport({
|
|
super.key,
|
|
required this.controller,
|
|
required this.contentSize,
|
|
required this.child,
|
|
this.onExpand,
|
|
this.showControls = true,
|
|
});
|
|
|
|
final GraphViewportController controller;
|
|
|
|
/// The measured graph extent; the canvas never invents a fixed size.
|
|
final Size contentSize;
|
|
|
|
/// The measured, already-routed graph content.
|
|
final Widget child;
|
|
|
|
/// Opens the expanded presentation. Null hides the expand control.
|
|
final VoidCallback? onExpand;
|
|
|
|
/// Whether this canvas draws its own fit/expand pill. Full-screen graph
|
|
/// views place Fit in their top-bar actions instead.
|
|
final bool showControls;
|
|
|
|
@override
|
|
State<GraphViewport> createState() => _GraphViewportState();
|
|
}
|
|
|
|
class _GraphViewportState extends State<GraphViewport> {
|
|
Size? _scheduledViewport;
|
|
Size? _scheduledContent;
|
|
|
|
@override
|
|
void didUpdateWidget(GraphViewport oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (oldWidget.controller != widget.controller) {
|
|
_scheduledViewport = null;
|
|
_scheduledContent = null;
|
|
}
|
|
}
|
|
|
|
/// Attaches the current extents after layout, never during build.
|
|
void _scheduleAttach(Size viewport) {
|
|
if (viewport == _scheduledViewport &&
|
|
widget.contentSize == _scheduledContent) {
|
|
return;
|
|
}
|
|
_scheduledViewport = viewport;
|
|
_scheduledContent = widget.contentSize;
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (!mounted) return;
|
|
widget.controller.attach(viewport: viewport, content: widget.contentSize);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final viewport =
|
|
constraints.hasBoundedWidth && constraints.hasBoundedHeight
|
|
? constraints.biggest
|
|
: widget.contentSize;
|
|
if (!widget.controller.isAttached) {
|
|
// The very first layout has no `InteractiveViewer` listening yet, so
|
|
// fitting here applies before the first paint instead of flashing an
|
|
// identity transform for one frame.
|
|
widget.controller.attach(
|
|
viewport: viewport,
|
|
content: widget.contentSize,
|
|
);
|
|
_scheduledViewport = viewport;
|
|
_scheduledContent = widget.contentSize;
|
|
} else {
|
|
_scheduleAttach(viewport);
|
|
}
|
|
return Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
Positioned.fill(
|
|
child: InteractiveViewer(
|
|
key: const Key('graph-viewport'),
|
|
transformationController: widget.controller.transformation,
|
|
constrained: false,
|
|
// The graph owns its own bounds (fit and the visible-pan clamp),
|
|
// so the viewer must not impose a second, cover-the-viewport
|
|
// boundary that would fight the fit scale.
|
|
boundaryMargin: const EdgeInsets.all(double.infinity),
|
|
minScale: widget.controller.minScale,
|
|
maxScale: widget.controller.maxScale,
|
|
clipBehavior: Clip.hardEdge,
|
|
child: SizedBox.fromSize(
|
|
size: widget.contentSize,
|
|
child: widget.child,
|
|
),
|
|
),
|
|
),
|
|
if (widget.showControls)
|
|
PositionedDirectional(
|
|
top: 8,
|
|
end: 8,
|
|
child: GlassPill(
|
|
child: Wrap(
|
|
spacing: 2,
|
|
children: [
|
|
_ViewportButton(
|
|
buttonKey: const Key('graph-fit'),
|
|
icon: Icons.fit_screen,
|
|
label: graphFitLabel,
|
|
onPressed: widget.controller.fitToViewport,
|
|
),
|
|
if (widget.onExpand != null)
|
|
_ViewportButton(
|
|
buttonKey: const Key('graph-expand'),
|
|
icon: Icons.fullscreen,
|
|
label: graphExpandLabel,
|
|
onPressed: widget.onExpand,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
/// One native graph control inside the shared floating glass pill.
|
|
///
|
|
/// The label and the button's own tap action must reach the same semantics
|
|
/// node: the icon is the only excluded child, and [MergeSemantics] folds the
|
|
/// host button's action into the labelled node, so a screen reader can activate
|
|
/// Fit and Expand. A hand-written `Semantics` sibling around an
|
|
/// excluded button would announce the control with no action at all.
|
|
class _ViewportButton extends StatelessWidget {
|
|
const _ViewportButton({
|
|
required this.buttonKey,
|
|
required this.icon,
|
|
required this.label,
|
|
required this.onPressed,
|
|
});
|
|
|
|
final Key buttonKey;
|
|
final IconData icon;
|
|
final String label;
|
|
final VoidCallback? onPressed;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MergeSemantics(
|
|
child: Semantics(
|
|
button: true,
|
|
label: label,
|
|
child: Tooltip(
|
|
message: label,
|
|
// The merged node already carries the label; the tooltip is
|
|
// only the pointer affordance.
|
|
excludeFromSemantics: true,
|
|
child: IconButton(
|
|
key: buttonKey,
|
|
onPressed: onPressed,
|
|
icon: ExcludeSemantics(child: Icon(icon)),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|