Files
pipelines/app/lib/shell/detail_page.dart
T
alan 963adec122 Float glass tab bars everywhere the app has bottom tabs
One floating frosted tab bar (host NavigationBar / CupertinoTabBar in the
shared GlassPill) replaces the NavigationRail, the Cupertino sidebar and the
run detail, stage page and pipeline detail tab strips. Below 600px it spans
the width minus 16px margins; wider it is sized to its tabs at the right edge.
Content keeps the full width, scrolls behind the bar and learns its height as
bottom media padding; lists pad their end clear of it and FABs sit above it.

The bar now sizes itself from its own constraints instead of the screen size,
which fixes the widget_test failure where a MediaQuery without a size gave it
negative width constraints.
2026-10-31 01:50:42 +00:00

164 lines
5.5 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../ui/adaptive/host.dart';
import '../ui/adaptive/segmented_bar.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;
final cupertino = usesCupertinoHost(context);
final bar = barless
? null
: SegmentedBar(
cupertino: cupertino,
automaticallyImplyLeading: widget.implyBack,
title: title,
actions: actions,
);
// The bottom inset (the system's, or a floating tab bar's when the
// pane sits beside a list) passes through: the open item's content
// floats its own tabs above it and pads its lists clear of it.
if (cupertino) {
return CupertinoPageScaffold(
navigationBar: bar,
child: SafeArea(bottom: false, child: body),
);
}
return Scaffold(
extendBodyBehindAppBar: true,
appBar: bar,
body: SafeArea(bottom: false, child: body),
);
},
);
}
}