wip(app): preserve partial runs navigation before native widget slices
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
|
||||||
import '../../core/api_gateway.dart';
|
import '../../core/api_gateway.dart';
|
||||||
import 'data/runs_repository.dart';
|
import 'data/runs_repository.dart';
|
||||||
@@ -17,6 +18,7 @@ class RunsScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _RunsScreenState extends State<RunsScreen> {
|
class _RunsScreenState extends State<RunsScreen> {
|
||||||
late RunsController controller;
|
late RunsController controller;
|
||||||
|
num? _selectedRunId;
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -38,7 +40,41 @@ class _RunsScreenState extends State<RunsScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => controller.detail == null
|
Widget build(BuildContext context) {
|
||||||
? RunsList(controller: controller)
|
final isCupertino = Theme.of(context).platform == TargetPlatform.iOS;
|
||||||
: RunDetailView(controller: controller);
|
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';
|
import 'runs_controller.dart';
|
||||||
|
|
||||||
class RunDetailView extends StatelessWidget {
|
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 RunsController controller;
|
||||||
|
final VoidCallback onBack;
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final run = controller.detail;
|
final run = controller.detail;
|
||||||
@@ -18,7 +19,7 @@ class RunDetailView extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Text(controller.error ?? 'Run details unavailable.'),
|
Text(controller.error ?? 'Run details unavailable.'),
|
||||||
FilledButton(
|
FilledButton(
|
||||||
onPressed: controller.back,
|
onPressed: onBack,
|
||||||
child: const Text('Back to runs'),
|
child: const Text('Back to runs'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -33,7 +34,7 @@ class RunDetailView extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
children: [
|
children: [
|
||||||
TextButton.icon(
|
TextButton.icon(
|
||||||
onPressed: controller.back,
|
onPressed: onBack,
|
||||||
icon: const Icon(Icons.arrow_back),
|
icon: const Icon(Icons.arrow_back),
|
||||||
label: const Text('Runs'),
|
label: const Text('Runs'),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ import 'runs_controller.dart';
|
|||||||
import '../domain/run_models.dart';
|
import '../domain/run_models.dart';
|
||||||
|
|
||||||
class RunsList extends StatelessWidget {
|
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 RunsController controller;
|
||||||
|
final ValueChanged<num> onSelected;
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (controller.loading && controller.runs.isEmpty) {
|
if (controller.loading && controller.runs.isEmpty) {
|
||||||
@@ -72,7 +73,7 @@ class RunsList extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
leading: Chip(label: Text(runStatusLabel(run))),
|
leading: Chip(label: Text(runStatusLabel(run))),
|
||||||
trailing: const Icon(Icons.chevron_right),
|
trailing: const Icon(Icons.chevron_right),
|
||||||
onTap: id is num ? () => controller.select(id) : null,
|
onTap: id is num ? () => onSelected(id) : null,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user