128 lines
3.6 KiB
Dart
128 lines
3.6 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../core/api_gateway.dart';
|
|
import '../features/templates/screen.dart';
|
|
import '../ui/adaptive/host.dart';
|
|
import 'app_session.dart';
|
|
import 'connection_status.dart';
|
|
import 'server_endpoint.dart';
|
|
|
|
/// The Back control of the app-level Templates page.
|
|
const templatesPageBackKey = ValueKey<String>('templates-page-back');
|
|
|
|
/// The Templates destination: the landed gallery over the app's shared gateway.
|
|
///
|
|
/// The gallery is rendered in embedded mode, so the shell owns navigation; this
|
|
/// destination contributes the page's one native bar (Back + Templates) and the
|
|
/// same honest connection states as the other destinations. No socket is opened
|
|
/// here: [session] owns the only connection, and a template read, validate or
|
|
/// create request travels over it.
|
|
///
|
|
/// [onCreated] forwards the server-confirmed detail once, so the caller can
|
|
/// invalidate the Pipelines list. This screen never inserts a row itself.
|
|
class TemplatesDestination extends StatelessWidget {
|
|
const TemplatesDestination({
|
|
super.key,
|
|
required this.session,
|
|
required this.server,
|
|
required this.onBack,
|
|
this.onCreated,
|
|
this.initialKey,
|
|
});
|
|
|
|
final AppSession session;
|
|
final ServerEndpoint server;
|
|
|
|
/// Closes this page and restores the Settings destination underneath.
|
|
final VoidCallback onBack;
|
|
final ValueChanged<JsonMap>? onCreated;
|
|
|
|
/// The template detail the route names, or null for the gallery.
|
|
final String? initialKey;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino = usesCupertinoHost(context);
|
|
return AnimatedBuilder(
|
|
animation: session,
|
|
builder: (context, _) => _TemplatesPage(
|
|
cupertino: cupertino,
|
|
onBack: onBack,
|
|
child: _body(cupertino),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _body(bool cupertino) {
|
|
if (!session.everConnected) {
|
|
return ConnectionGate(
|
|
session: session,
|
|
server: server,
|
|
cupertino: cupertino,
|
|
);
|
|
}
|
|
return Column(
|
|
children: [
|
|
if (!session.connected)
|
|
ConnectionBanner(session: session, cupertino: cupertino),
|
|
Expanded(
|
|
child: TemplatesScreen(
|
|
gateway: session.gateway,
|
|
embedded: true,
|
|
onCreated: onCreated,
|
|
initialKey: initialKey,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The page's standard native bar. Back is named explicitly so it cannot be
|
|
/// confused with the gallery's own Back-to-gallery control.
|
|
class _TemplatesPage extends StatelessWidget {
|
|
const _TemplatesPage({
|
|
required this.cupertino,
|
|
required this.onBack,
|
|
required this.child,
|
|
});
|
|
|
|
final bool cupertino;
|
|
final VoidCallback onBack;
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (cupertino) {
|
|
return CupertinoPageScaffold(
|
|
navigationBar: CupertinoNavigationBar(
|
|
leading: CupertinoButton(
|
|
key: templatesPageBackKey,
|
|
padding: EdgeInsets.zero,
|
|
onPressed: onBack,
|
|
child: const Icon(
|
|
CupertinoIcons.back,
|
|
semanticLabel: 'Back to Settings',
|
|
),
|
|
),
|
|
middle: const Text('Templates'),
|
|
),
|
|
child: SafeArea(child: child),
|
|
);
|
|
}
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
leading: IconButton(
|
|
key: templatesPageBackKey,
|
|
tooltip: 'Back to Settings',
|
|
onPressed: onBack,
|
|
icon: const Icon(Icons.arrow_back),
|
|
),
|
|
title: const Text('Templates'),
|
|
),
|
|
body: SafeArea(child: child),
|
|
);
|
|
}
|
|
}
|