feat(app): register the saved-schedule list under Settings at /schedules
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../features/schedules/data/schedules_repository.dart';
|
||||
import '../features/schedules/ui/list/schedule_list_controller.dart';
|
||||
import '../features/schedules/ui/list/schedule_list_view.dart';
|
||||
import '../ui/adaptive/host.dart';
|
||||
import 'app_session.dart';
|
||||
import 'server_endpoint.dart';
|
||||
|
||||
/// The saved-schedule list above Settings.
|
||||
///
|
||||
/// It is read-only: opening a row asks the composition to show the owning
|
||||
/// pipeline's Summary, where the landed section owns create/edit/pause/delete.
|
||||
/// The list never saves, pauses or deletes anything itself.
|
||||
class SchedulesDestination extends StatefulWidget {
|
||||
const SchedulesDestination({
|
||||
super.key,
|
||||
required this.session,
|
||||
required this.server,
|
||||
required this.onBack,
|
||||
required this.onOpenPipeline,
|
||||
});
|
||||
|
||||
final AppSession session;
|
||||
final ServerEndpoint server;
|
||||
final VoidCallback onBack;
|
||||
final ValueChanged<int> onOpenPipeline;
|
||||
|
||||
@override
|
||||
State<SchedulesDestination> createState() => _SchedulesDestinationState();
|
||||
}
|
||||
|
||||
class _SchedulesDestinationState extends State<SchedulesDestination> {
|
||||
late final SchedulesController _controller;
|
||||
final TextEditingController _search = TextEditingController();
|
||||
final ScrollController _scroll = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = SchedulesController(
|
||||
repository: SchedulesRepository(widget.session.gateway),
|
||||
);
|
||||
unawaited(_controller.refresh());
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(SchedulesDestination oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.session.gateway != widget.session.gateway) {
|
||||
// A different server lists different schedules; re-read through the same
|
||||
// controller so the screen is never shown with the old server's rows.
|
||||
unawaited(_controller.refresh());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
_search.dispose();
|
||||
_scroll.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
final page = _page(cupertino);
|
||||
return AnimatedBuilder(
|
||||
animation: widget.session,
|
||||
builder: (context, _) => page,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _page(bool cupertino) {
|
||||
final body = _body(cupertino);
|
||||
if (cupertino) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
leading: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: widget.onBack,
|
||||
child: const Icon(CupertinoIcons.back, semanticLabel: 'Back'),
|
||||
),
|
||||
middle: const Text('Schedules'),
|
||||
),
|
||||
child: SafeArea(child: body),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
onPressed: widget.onBack,
|
||||
icon: const Icon(Icons.arrow_back, semanticLabel: 'Back'),
|
||||
),
|
||||
title: const Text('Schedules'),
|
||||
),
|
||||
body: body,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _body(bool cupertino) {
|
||||
if (!widget.session.everConnected) {
|
||||
return const Center(child: Text('Connect to the server to see schedules.'));
|
||||
}
|
||||
return SchedulesListView(
|
||||
controller: _controller,
|
||||
searchController: _search,
|
||||
scrollController: _scroll,
|
||||
cupertino: cupertino,
|
||||
onOpen: (schedule) {
|
||||
final id = schedule.pipelineId;
|
||||
if (id != null) widget.onOpenPipeline(id);
|
||||
},
|
||||
onRefresh: () => _controller.refresh(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user