wip(app): preserve partial runs navigation before native widget slices

This commit is contained in:
2026-10-21 13:56:09 +01:00
parent 6b8d5ea32e
commit b2b2b56fd3
3 changed files with 46 additions and 8 deletions
+39 -3
View File
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import '../../core/api_gateway.dart';
import 'data/runs_repository.dart';
@@ -17,6 +18,7 @@ class RunsScreen extends StatefulWidget {
class _RunsScreenState extends State<RunsScreen> {
late RunsController controller;
num? _selectedRunId;
@override
void initState() {
super.initState();
@@ -38,7 +40,41 @@ class _RunsScreenState extends State<RunsScreen> {
}
@override
Widget build(BuildContext context) => controller.detail == null
? RunsList(controller: controller)
: RunDetailView(controller: controller);
Widget build(BuildContext context) {
final isCupertino = Theme.of(context).platform == TargetPlatform.iOS;
final selected = _selectedRunId != null;
final content = Stack(
children: [
Offstage(
offstage: selected,
child: RunsList(controller: controller, onSelected: (id) {
setState(() => _selectedRunId = id);
controller.select(id);
}),
),
if (selected)
RunDetailView(
controller: controller,
onBack: () {
controller.back();
setState(() => _selectedRunId = null);
},
),
],
);
if (isCupertino) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text(selected ? 'Run ${controller.detail?['id'] ?? _selectedRunId}' : 'Runs'),
leading: selected ? CupertinoButton(
padding: EdgeInsets.zero,
onPressed: () { controller.back(); setState(() => _selectedRunId = null); },
child: const Text('Runs'),
) : null,
),
child: SafeArea(child: content),
);
}
return content;
}
}
@@ -3,8 +3,9 @@ import 'package:flutter/services.dart';
import 'runs_controller.dart';
class RunDetailView extends StatelessWidget {
const RunDetailView({super.key, required this.controller});
const RunDetailView({super.key, required this.controller, required this.onBack});
final RunsController controller;
final VoidCallback onBack;
@override
Widget build(BuildContext context) {
final run = controller.detail;
@@ -18,7 +19,7 @@ class RunDetailView extends StatelessWidget {
children: [
Text(controller.error ?? 'Run details unavailable.'),
FilledButton(
onPressed: controller.back,
onPressed: onBack,
child: const Text('Back to runs'),
),
],
@@ -33,7 +34,7 @@ class RunDetailView extends StatelessWidget {
padding: const EdgeInsets.all(16),
children: [
TextButton.icon(
onPressed: controller.back,
onPressed: onBack,
icon: const Icon(Icons.arrow_back),
label: const Text('Runs'),
),
+3 -2
View File
@@ -3,8 +3,9 @@ import 'runs_controller.dart';
import '../domain/run_models.dart';
class RunsList extends StatelessWidget {
const RunsList({super.key, required this.controller});
const RunsList({super.key, required this.controller, required this.onSelected});
final RunsController controller;
final ValueChanged<num> onSelected;
@override
Widget build(BuildContext context) {
if (controller.loading && controller.runs.isEmpty) {
@@ -72,7 +73,7 @@ class RunsList extends StatelessWidget {
),
leading: Chip(label: Text(runStatusLabel(run))),
trailing: const Icon(Icons.chevron_right),
onTap: id is num ? () => controller.select(id) : null,
onTap: id is num ? () => onSelected(id) : null,
);
},
),