118 lines
3.6 KiB
Dart
118 lines
3.6 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/host.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 cupertino = usesCupertinoHost(context);
|
|
final executedColor = cupertino
|
|
? CupertinoTheme.of(context).primaryColor
|
|
: 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: cupertino
|
|
? CupertinoIcons.arrow_right
|
|
: Icons.arrow_forward,
|
|
label: runGraphExecuted,
|
|
color: executedColor,
|
|
),
|
|
_LegendEntry(
|
|
icon: cupertino ? CupertinoIcons.minus : 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';
|
|
}
|