feat(app): finish native run Changes wiring and scaled form menus
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../../changes/changes.dart';
|
||||
|
||||
/// The run detail's action and page label. The viewer itself owns the
|
||||
/// recorded summary and capture wording, so this bar stays neutral.
|
||||
const runChangesLabel = 'Changes';
|
||||
const runChangesButtonKey = ValueKey<String>('run-detail-changes');
|
||||
|
||||
/// The detail's `steps` exactly as returned by the server. The pushed page
|
||||
/// snapshots the returned list once, so it never re-derives on each rebuild.
|
||||
List<JsonMap> runDetailChangeSteps(JsonMap run) {
|
||||
final steps = run['steps'];
|
||||
if (steps is List<JsonMap>) return steps;
|
||||
if (steps is List) return steps.cast<JsonMap>();
|
||||
return const <JsonMap>[];
|
||||
}
|
||||
|
||||
const _executingStatuses = {'queued', 'running', 'waiting'};
|
||||
|
||||
/// Whether the run detail offers the action at all. The opened page is a
|
||||
/// snapshot of the recorded steps, so it is offered only once nothing is
|
||||
/// executing: the server's own `executing` flag (which can stay true on a
|
||||
/// failed run whose step is still active) or a queued/running/waiting status
|
||||
/// would otherwise show a page that silently goes stale.
|
||||
bool showRunChangesAction(JsonMap run) =>
|
||||
run['executing'] != true &&
|
||||
!_executingStatuses.contains('${run['status'] ?? ''}'.trim().toLowerCase());
|
||||
|
||||
/// A standard native button for the run detail body. It opens the recorded
|
||||
/// changes in a platform page whose single navigation bar is the only chrome.
|
||||
class RunChangesButton extends StatelessWidget {
|
||||
const RunChangesButton({super.key, required this.run});
|
||||
|
||||
final JsonMap run;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final steps = runDetailChangeSteps(run);
|
||||
// The web client shows the run-wide aggregate only for a succeeded run; a
|
||||
// failed run still keeps each visit's own recorded capture.
|
||||
final summary = showRunChangesSummary(run['status']);
|
||||
void open() => showRunChanges(context, steps: steps, showSummary: summary);
|
||||
if (usesCupertinoHost(context)) {
|
||||
return CupertinoButton.tinted(
|
||||
key: runChangesButtonKey,
|
||||
onPressed: open,
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(CupertinoIcons.doc_text),
|
||||
SizedBox(width: 6),
|
||||
Text(runChangesLabel),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return FilledButton.tonalIcon(
|
||||
key: runChangesButtonKey,
|
||||
onPressed: open,
|
||||
icon: const Icon(Icons.difference_outlined),
|
||||
label: const Text(runChangesLabel),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens the already-landed [ChangesViewer] for [steps] on a native page.
|
||||
/// The bar is the one title bar; the viewer's own summary and capture facts
|
||||
/// are passed through untouched, except for the caller's [showSummary] gate.
|
||||
Future<void> showRunChanges(
|
||||
BuildContext context, {
|
||||
required List<JsonMap> steps,
|
||||
required bool showSummary,
|
||||
}) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
return Navigator.of(context).push<void>(
|
||||
cupertino
|
||||
? CupertinoPageRoute<void>(
|
||||
builder: (_) =>
|
||||
_CupertinoChangesPage(steps: steps, showSummary: showSummary),
|
||||
)
|
||||
: MaterialPageRoute<void>(
|
||||
builder: (_) =>
|
||||
_MaterialChangesPage(steps: steps, showSummary: showSummary),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _MaterialChangesPage extends StatelessWidget {
|
||||
const _MaterialChangesPage({required this.steps, required this.showSummary});
|
||||
|
||||
final List<JsonMap> steps;
|
||||
final bool showSummary;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(title: const Text(runChangesLabel)),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: ChangesViewer(steps: steps, showSummary: showSummary),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _CupertinoChangesPage extends StatelessWidget {
|
||||
const _CupertinoChangesPage({required this.steps, required this.showSummary});
|
||||
|
||||
final List<JsonMap> steps;
|
||||
final bool showSummary;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(middle: Text(runChangesLabel)),
|
||||
child: SafeArea(
|
||||
// A CupertinoApp supplies no Material theme; follow the host brightness
|
||||
// so the viewer's Material-derived section text stays readable.
|
||||
child: Theme(
|
||||
data: hostTextTheme(context),
|
||||
child: ChangesViewer(steps: steps, showSummary: showSummary),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../domain/run_models.dart';
|
||||
import 'run_changes_action.dart';
|
||||
import 'run_detail_content.dart';
|
||||
|
||||
/// The runs detail with standard Cupertino controls. It has no Material
|
||||
@@ -26,7 +27,11 @@ Widget buildCupertinoRunDetail({
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||
child: Row(
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
@@ -40,7 +45,7 @@ Widget buildCupertinoRunDetail({
|
||||
],
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (showRunChangesAction(run)) RunChangesButton(run: run),
|
||||
if (copying) const CupertinoActivityIndicator(),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../domain/run_models.dart';
|
||||
import 'run_changes_action.dart';
|
||||
import 'run_detail_content.dart';
|
||||
|
||||
/// The runs detail with standard Material controls.
|
||||
@@ -23,13 +24,18 @@ Widget buildMaterialRunDetail({
|
||||
key: ValueKey<String>('run-detail-${run['id']}'),
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: TextButton.icon(
|
||||
onPressed: onBack,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const Text('Back to list'),
|
||||
),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: onBack,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const Text('Back to list'),
|
||||
),
|
||||
if (showRunChangesAction(run)) RunChangesButton(run: run),
|
||||
],
|
||||
),
|
||||
Text(detailTitle(run), style: theme.textTheme.headlineSmall),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
Reference in New Issue
Block a user