Files
pipelines/app/lib/features/runs/screen.dart
T

81 lines
2.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import '../../core/api_gateway.dart';
import 'data/runs_repository.dart';
import 'ui/runs_controller.dart';
import 'ui/runs_list.dart';
import 'ui/run_detail_view.dart';
class RunsScreen extends StatefulWidget {
const RunsScreen({super.key, required this.gateway, this.initialRunId});
final ApiGateway gateway;
final int? initialRunId;
@override
State<RunsScreen> createState() => _RunsScreenState();
}
class _RunsScreenState extends State<RunsScreen> {
late RunsController controller;
num? _selectedRunId;
@override
void initState() {
super.initState();
controller = RunsController(RunsRepository(widget.gateway));
controller.listen(widget.gateway.frames);
controller.addListener(_changed);
controller.load(widget.initialRunId);
}
void _changed() {
if (mounted) setState(() {});
}
@override
void dispose() {
controller.removeListener(_changed);
controller.dispose();
super.dispose();
}
@override
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;
}
}