963adec122
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.
247 lines
8.1 KiB
Dart
247 lines
8.1 KiB
Dart
import '../ui/motion/motion.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../ui/adaptive/segmented_bar.dart';
|
|
import '../ui/adaptive/floating_bar_layout.dart';
|
|
import '../ui/adaptive/floating_destination_bar.dart';
|
|
import 'attention_badge.dart';
|
|
import 'destination.dart';
|
|
import 'shell_bar.dart';
|
|
|
|
class AdaptiveShell extends StatefulWidget {
|
|
const AdaptiveShell({
|
|
super.key,
|
|
this.destinationBodies = const {},
|
|
this.cupertino = false,
|
|
this.destination,
|
|
this.onDestinationSelected,
|
|
this.onSearch,
|
|
this.attentionCount = 0,
|
|
});
|
|
|
|
final Map<AppDestination, WidgetBuilder> destinationBodies;
|
|
final bool cupertino;
|
|
|
|
/// The destination a route owner selected. When null the shell keeps its own
|
|
/// selection, which preserves the plain-shell tests and native composition.
|
|
final AppDestination? destination;
|
|
final ValueChanged<AppDestination>? onDestinationSelected;
|
|
|
|
/// Opens the transient Search page. Null hides the action, so the plain
|
|
/// shell tests and compositions without routing keep their tab set only.
|
|
final VoidCallback? onSearch;
|
|
|
|
/// Runs needing the operator today, mirrored on the Runs tab in every mount
|
|
/// so it stays visible from any destination. Zero shows no badge.
|
|
final int attentionCount;
|
|
|
|
@override
|
|
State<AdaptiveShell> createState() => _AdaptiveShellState();
|
|
}
|
|
|
|
class _AdaptiveShellState extends State<AdaptiveShell> {
|
|
late AppDestination _selected;
|
|
final Set<AppDestination> _visited = {};
|
|
final ShellBarRegistry _bar = ShellBarRegistry();
|
|
// Keeps every destination's state if the stack's parent ever changes.
|
|
final GlobalKey _destinationStackKey = GlobalKey();
|
|
|
|
@override
|
|
void dispose() {
|
|
_bar.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_selected = widget.destination ?? AppDestination.pipelines;
|
|
_visited.add(_selected);
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant AdaptiveShell oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
final destination = widget.destination;
|
|
if (destination != null) {
|
|
_selected = destination;
|
|
_visited.add(destination);
|
|
}
|
|
}
|
|
|
|
void _select(AppDestination destination) {
|
|
final callback = widget.onDestinationSelected;
|
|
if (callback != null) {
|
|
callback(destination);
|
|
return;
|
|
}
|
|
setState(() {
|
|
_selected = destination;
|
|
_visited.add(destination);
|
|
});
|
|
}
|
|
|
|
/// The destination's icon; only Runs carries the attention count.
|
|
Widget _icon(AppDestination destination, IconData data) {
|
|
Widget icon = Icon(data);
|
|
if (destination == AppDestination.chat) {
|
|
return ActivityBadge(
|
|
key: const ValueKey('shell.badge.chat.unread'),
|
|
count: _bar.badge(destination, ShellBadgeKind.unread),
|
|
label: 'unread chats',
|
|
cupertino: widget.cupertino,
|
|
child: icon,
|
|
);
|
|
}
|
|
if (destination != AppDestination.runs) return icon;
|
|
// Runs in progress at the bottom, runs that need you at the top.
|
|
icon = ActivityBadge(
|
|
key: const ValueKey('shell.badge.runs.running'),
|
|
count: _bar.badge(destination, ShellBadgeKind.running),
|
|
label: 'runs in progress',
|
|
cupertino: widget.cupertino,
|
|
bottom: true,
|
|
child: icon,
|
|
);
|
|
return AttentionDestinationIcon(
|
|
count: widget.attentionCount,
|
|
cupertino: widget.cupertino,
|
|
child: icon,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Full-screen detail routes cover the shell themselves. Keep the root tabs
|
|
// mounted/layout-ready underneath, so Back does not resize or reveal them
|
|
// only after the outgoing page has finished its native animation.
|
|
final index = AppDestination.values.indexOf(_selected);
|
|
final details = destinationDetails(_selected);
|
|
final contents = AppDestination.values.map((destination) {
|
|
final item = destinationDetails(destination);
|
|
return KeyedSubtree(
|
|
key: ValueKey(destination),
|
|
child: ShellBarScope(
|
|
registry: _bar,
|
|
destination: destination,
|
|
child: _visited.contains(destination)
|
|
? widget.destinationBodies[destination]?.call(context) ??
|
|
Center(child: Text('${item.label} — Not implemented'))
|
|
: const SizedBox.shrink(),
|
|
),
|
|
);
|
|
}).toList();
|
|
return ListenableBuilder(
|
|
listenable: _bar,
|
|
builder: (context, _) {
|
|
final spec = _bar.specFor(_selected);
|
|
// One floating glass tab bar at every width: full width on a phone,
|
|
// sized to its tabs at the right edge on a wide window (the bar judges
|
|
// that itself, live). Content keeps the whole width and scrolls behind
|
|
// it, learning the bar's height as its bottom media padding. Neither
|
|
// scaffold's structure depends on the width, so resizing never
|
|
// remounts a destination.
|
|
final bar = FloatingDestinationBar(
|
|
cupertino: widget.cupertino,
|
|
currentIndex: index,
|
|
onTap: (value) => _select(AppDestination.values[value]),
|
|
items: _destinationItems(),
|
|
);
|
|
if (widget.cupertino) {
|
|
return CupertinoPageScaffold(
|
|
navigationBar: _segmentedBar(spec, details.label),
|
|
child: SafeArea(
|
|
bottom: false,
|
|
child: FloatingBarOverlay(
|
|
bar: bar,
|
|
child: _destinationStack(contents, index),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
return Scaffold(
|
|
extendBodyBehindAppBar: true,
|
|
appBar: _segmentedBar(spec, details.label),
|
|
// Destinations start below the floating top bar.
|
|
body: SafeArea(
|
|
left: false,
|
|
right: false,
|
|
bottom: false,
|
|
child: _destinationStack(contents, index),
|
|
),
|
|
extendBody: true,
|
|
bottomNavigationBar: bar,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
List<FloatingDestinationItem> _destinationItems() =>
|
|
AppDestination.values.map((destination) {
|
|
final item = destinationDetails(destination);
|
|
return FloatingDestinationItem(
|
|
key: ValueKey('shell.destination.${destination.name}'),
|
|
icon: _icon(
|
|
destination,
|
|
widget.cupertino ? item.cupertinoIcon : item.icon,
|
|
),
|
|
label: item.label,
|
|
);
|
|
}).toList();
|
|
|
|
/// The open screen's own bar: its Back, title and actions, or the tab's
|
|
/// name with Search.
|
|
SegmentedBar _segmentedBar(ShellBarSpec? spec, String label) {
|
|
final cupertino = widget.cupertino;
|
|
final onBack = spec?.onBack;
|
|
final published = spec?.actions ?? const <Widget>[];
|
|
final onSearch = widget.onSearch;
|
|
return SegmentedBar(
|
|
cupertino: cupertino,
|
|
automaticallyImplyLeading: false,
|
|
leading: onBack == null
|
|
? null
|
|
: SegmentedBackButton(
|
|
key: const ValueKey('shell.back'),
|
|
cupertino: cupertino,
|
|
onPressed: onBack,
|
|
),
|
|
title: spec?.title ?? label,
|
|
actions: [
|
|
if (published.isNotEmpty)
|
|
// A screen taking the bar over cross-fades its actions in.
|
|
MotionSwitcher(
|
|
child: Row(
|
|
key: ObjectKey(_bar.ownerFor(_selected)),
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
for (final action in published) Flexible(child: action),
|
|
],
|
|
),
|
|
)
|
|
else if (onSearch != null)
|
|
cupertino
|
|
? CupertinoButton(
|
|
key: const ValueKey('shell.search'),
|
|
padding: EdgeInsets.zero,
|
|
onPressed: onSearch,
|
|
child: const Icon(
|
|
CupertinoIcons.search,
|
|
semanticLabel: 'Search',
|
|
),
|
|
)
|
|
: IconButton(
|
|
key: const ValueKey('shell.search'),
|
|
onPressed: onSearch,
|
|
tooltip: 'Search',
|
|
icon: const Icon(Icons.search),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _destinationStack(List<Widget> contents, int index) =>
|
|
IndexedStack(key: _destinationStackKey, index: index, children: contents);
|
|
}
|