Files
alan 88cb76f220 Remove Cupertino graph branches
Keep the Material graph implementation while preserving public Cupertino parameters for callers. Remove unreachable Cupertino widgets, routes, theme branches, imports, and Cupertino-only tests because the app runs exclusively under MaterialApp.
2026-11-11 02:26:12 +00:00

111 lines
3.3 KiB
Dart

import 'package:flutter/material.dart';
import '../domain/run_graph_state.dart';
import 'graph_canvas_style.dart';
/// The run legend's route-class words (web graph legend).
const String runGraphExecuted = 'Executed';
const String runGraphNotExecuted = 'Not executed';
/// The run canvas' fixed header: the route legend, plus the elapsed line while
/// the run is still executing.
///
/// It is shared by the inline view and the full-screen presentation so the
/// expanded canvas explains its solid and dashed routes the way the web keeps
/// its legend inside the graph panel.
class RunGraphHeader extends StatelessWidget {
const RunGraphHeader({
super.key,
required this.state,
required this.style,
this.now,
});
final RunGraphState state;
final GraphCanvasStyle style;
/// Injectable clock for deterministic elapsed labels; defaults to now.
final DateTime Function()? now;
@override
Widget build(BuildContext context) {
final executedColor = Theme.of(context).colorScheme.primary;
final mutedColor = style.edgeColor;
final active = state.activeStage;
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(12, 8, 12, 0),
child: Wrap(
spacing: 16,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Semantics(
container: true,
label: 'Route kinds',
child: Wrap(
spacing: 12,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
_LegendEntry(
icon: Icons.arrow_forward,
label: runGraphExecuted,
color: executedColor,
),
_LegendEntry(
icon: Icons.remove,
label: runGraphNotExecuted,
color: mutedColor,
),
],
),
),
if (active != null)
_elapsed(context, active, state.currentStageStartedAt),
],
),
);
}
Widget _elapsed(BuildContext context, String active, String? startedAt) {
final started = startedAt == null ? null : DateTime.tryParse(startedAt);
final duration = started == null
? null
: _formatElapsed((now ?? DateTime.now)().difference(started));
final text = duration == null
? 'Current stage $active'
: 'Current stage $active · elapsed $duration';
return Text(text, style: GraphCanvasStyle.of(context).labelStyle);
}
}
class _LegendEntry extends StatelessWidget {
const _LegendEntry({
required this.icon,
required this.label,
required this.color,
});
final IconData icon;
final String label;
final Color color;
@override
Widget build(BuildContext context) => Wrap(
spacing: 4,
runSpacing: 2,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
ExcludeSemantics(child: Icon(icon, color: color)),
Text(label),
],
);
}
String _formatElapsed(Duration duration) {
final seconds = duration.inSeconds < 0 ? 0 : duration.inSeconds;
if (seconds < 60) return '${seconds}s';
if (seconds < 3600) return '${seconds ~/ 60}m ${seconds % 60}s';
return '${seconds ~/ 3600}h ${(seconds % 3600) ~/ 60}m';
}