9551eceaed
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
175 lines
6.0 KiB
Dart
175 lines
6.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../ui/adaptive/segmented_bar.dart';
|
|
import '../ui/motion/container_transform_route.dart';
|
|
import '../ui/motion/container_transform_source.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,
|
|
ContainerTransformLink? growFrom,
|
|
}) {
|
|
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,
|
|
growFrom: growFrom,
|
|
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.
|
|
///
|
|
/// With [growFrom] the page grows out of the list item that opened it and
|
|
/// shrinks back into it ([ContainerTransformPageRoute]); otherwise it enters
|
|
/// with the platform's page transition.
|
|
PageRoute<void> detailPageRoute(
|
|
BuildContext context, {
|
|
required AppDestination destination,
|
|
required WidgetBuilder builder,
|
|
ContainerTransformLink? growFrom,
|
|
}) {
|
|
final page = DetailPane(destination: destination, builder: builder);
|
|
if (growFrom != null) {
|
|
return ContainerTransformPageRoute<void>(
|
|
link: growFrom,
|
|
builder: (_) => page,
|
|
);
|
|
}
|
|
return 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;
|
|
final bar = barless
|
|
? null
|
|
: SegmentedBar(
|
|
automaticallyImplyLeading: widget.implyBack,
|
|
title: title,
|
|
subtitle: spec?.subtitle,
|
|
subtitleIcon: spec?.subtitleIcon,
|
|
onTitlePressed: spec?.onTitlePressed,
|
|
expandableTitle: spec?.expandableTitle ?? false,
|
|
titleAction: spec?.titleAction,
|
|
titleSemanticLabel: spec?.titleSemanticLabel,
|
|
titleKey: spec?.titleKey,
|
|
actions: actions,
|
|
);
|
|
// Both insets pass through: the content scrolls behind the bar and
|
|
// pads its lists by the bar's height (top) and by the system's or a
|
|
// floating tab bar's (bottom), floating its own tabs clear of them.
|
|
final content = SafeArea(top: false, bottom: false, child: body);
|
|
return Scaffold(
|
|
extendBodyBehindAppBar: true,
|
|
appBar: bar,
|
|
body: content,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|