4a85a12cf7
The open conversation draws its own bar of separate rounded pieces: the platform Back in a circle, a title pill with the folder that opens the chat information, and a pill with the model and mode controls. Detail pages drop only their app bar for it, keeping the body mounted.
175 lines
6.0 KiB
Dart
175 lines
6.0 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../ui/adaptive/host.dart';
|
|
import 'destination.dart';
|
|
import 'shell_bar.dart';
|
|
|
|
/// Keeps one full-screen detail page (an open run, pipeline or chat) in step
|
|
/// with a screen's selection: selecting pushes the page over the tabs, like a
|
|
/// new activity, and closing it (its Back, the system Back) clears the
|
|
/// selection. A selection cleared elsewhere (a route change) removes the page.
|
|
class DetailPageHost {
|
|
Route<void>? _route;
|
|
|
|
/// The owner's latest build of the page's content, so the open page
|
|
/// follows the owner's state (a renamed title, a newer reply).
|
|
final ValueNotifier<WidgetBuilder?> _content = ValueNotifier(null);
|
|
|
|
/// Whether the page is pushed (or about to be).
|
|
bool get open => _route != null;
|
|
|
|
void sync(
|
|
BuildContext context, {
|
|
required bool selected,
|
|
required AppDestination destination,
|
|
required WidgetBuilder builder,
|
|
required VoidCallback onClosed,
|
|
}) {
|
|
if (selected && _route != null) {
|
|
// Another route cannot be rebuilt mid-build; the page follows next frame.
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (_route != null) _content.value = builder;
|
|
});
|
|
}
|
|
if (selected && _route == null) {
|
|
_content.value = builder;
|
|
final route = detailPageRoute(
|
|
context,
|
|
destination: destination,
|
|
builder: (context) => ValueListenableBuilder<WidgetBuilder?>(
|
|
valueListenable: _content,
|
|
builder: (context, build, _) =>
|
|
build == null ? const SizedBox.shrink() : build(context),
|
|
),
|
|
);
|
|
_route = route;
|
|
// Pushing during a build is not allowed; the page follows this frame.
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (!context.mounted || _route != route) return;
|
|
Navigator.of(context).push(route);
|
|
route.completed.then((_) {
|
|
if (_route != route) return;
|
|
_route = null;
|
|
// Keep ownership until the route is actually gone. Live updates
|
|
// during its exit must not push a second copy of the detail page.
|
|
onClosed();
|
|
});
|
|
});
|
|
} else if (!selected && _route != null) {
|
|
final route = _route!;
|
|
_route = null;
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (route.isActive) route.navigator?.removeRoute(route);
|
|
});
|
|
}
|
|
}
|
|
|
|
/// Removes the page with its owner.
|
|
void dispose() {
|
|
// The notifier is left to the page: a page still animating out keeps
|
|
// listening to it until it is gone.
|
|
final route = _route;
|
|
_route = null;
|
|
if (route != null && route.isActive) route.navigator?.removeRoute(route);
|
|
}
|
|
}
|
|
|
|
/// A full-screen page whose bar shows what the page's content publishes
|
|
/// through [ShellBar] (title and actions), with the platform's Back.
|
|
PageRoute<void> detailPageRoute(
|
|
BuildContext context, {
|
|
required AppDestination destination,
|
|
required WidgetBuilder builder,
|
|
}) {
|
|
final page = DetailPane(destination: destination, builder: builder);
|
|
return usesCupertinoHost(context)
|
|
? CupertinoPageRoute<void>(builder: (_) => page)
|
|
: MaterialPageRoute<void>(builder: (_) => page);
|
|
}
|
|
|
|
/// An open item's own bar over its content: what the content publishes
|
|
/// through [ShellBar] (title and actions). As a pushed page it implies the
|
|
/// platform's Back; inline beside a list ([implyBack] false) it shows none.
|
|
class DetailPane extends StatefulWidget {
|
|
const DetailPane({
|
|
super.key,
|
|
required this.destination,
|
|
required this.builder,
|
|
this.implyBack = true,
|
|
});
|
|
|
|
final AppDestination destination;
|
|
final WidgetBuilder builder;
|
|
final bool implyBack;
|
|
|
|
@override
|
|
State<DetailPane> createState() => _DetailPaneState();
|
|
}
|
|
|
|
class _DetailPaneState extends State<DetailPane> {
|
|
final ShellBarRegistry _bar = ShellBarRegistry();
|
|
|
|
@override
|
|
void dispose() {
|
|
_bar.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final body = ShellBarScope(
|
|
registry: _bar,
|
|
destination: widget.destination,
|
|
child: Builder(builder: widget.builder),
|
|
);
|
|
return ListenableBuilder(
|
|
listenable: _bar,
|
|
builder: (context, _) {
|
|
final spec = _bar.specFor(widget.destination);
|
|
final title = spec?.title ?? '';
|
|
final actions = spec?.actions ?? const <Widget>[];
|
|
// Content with its own bar reaches the top edge and owns the
|
|
// status-bar inset itself. The scaffold and the body's place in it stay
|
|
// the same either way, so switching never remounts the content.
|
|
final barless = spec?.barless ?? false;
|
|
if (usesCupertinoHost(context)) {
|
|
return CupertinoPageScaffold(
|
|
navigationBar: barless
|
|
? null
|
|
: CupertinoNavigationBar(
|
|
automaticallyImplyLeading: widget.implyBack,
|
|
// Inline pane bars are not routes and must not join the shell's
|
|
// navigation-bar hero when resizing into a pushed phone page.
|
|
transitionBetweenRoutes: widget.implyBack,
|
|
middle: Text(title),
|
|
trailing: actions.isEmpty
|
|
? null
|
|
: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
for (final action in actions)
|
|
Flexible(child: action),
|
|
],
|
|
),
|
|
),
|
|
child: SafeArea(child: body),
|
|
);
|
|
}
|
|
return Scaffold(
|
|
appBar: barless
|
|
? null
|
|
: AppBar(
|
|
automaticallyImplyLeading: widget.implyBack,
|
|
title: Text(title),
|
|
actions: [
|
|
for (final action in actions) Flexible(child: action),
|
|
],
|
|
),
|
|
body: SafeArea(top: false, child: body),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|