feat(app): an open run takes over the app bar (Back, run, more menu); Search is the fifth tab; tabs keep their last screen

This commit is contained in:
2026-10-23 17:47:05 +01:00
parent 30e3f22a1c
commit 14a556ebd9
13 changed files with 606 additions and 289 deletions
+140 -101
View File
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'attention_badge.dart';
import 'destination.dart';
import 'shell_bar.dart';
class AdaptiveShell extends StatefulWidget {
const AdaptiveShell({
@@ -38,6 +39,13 @@ class AdaptiveShell extends StatefulWidget {
class _AdaptiveShellState extends State<AdaptiveShell> {
late AppDestination _selected;
final Set<AppDestination> _visited = {};
final ShellBarRegistry _bar = ShellBarRegistry();
@override
void dispose() {
_bar.dispose();
super.dispose();
}
@override
void initState() {
@@ -90,114 +98,145 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
final item = destinationDetails(destination);
return KeyedSubtree(
key: ValueKey(destination),
child: _visited.contains(destination)
? widget.destinationBodies[destination]?.call(context) ??
Center(child: Text('${item.label} — Not implemented'))
: const SizedBox.shrink(),
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 LayoutBuilder(
builder: (context, constraints) {
final wide = constraints.maxWidth >= 600;
if (widget.cupertino) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text(details.label),
trailing: widget.onSearch == null
? null
: CupertinoButton(
key: const ValueKey('shell.search'),
padding: EdgeInsets.zero,
onPressed: widget.onSearch,
child: const Icon(
CupertinoIcons.search,
semanticLabel: 'Search',
return ListenableBuilder(
listenable: _bar,
builder: (context, _) => LayoutBuilder(
builder: (context, constraints) {
final wide = constraints.maxWidth >= 600;
if (widget.cupertino) {
final spec = _bar.specFor(_selected);
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
// The open screen's own bar: its Back, title and actions.
leading: spec?.onBack == null
? null
: CupertinoNavigationBarBackButton(
key: const ValueKey('shell.back'),
onPressed: spec!.onBack,
),
),
),
child: SafeArea(
child: wide
// The web keeps a destination rail on a wide window. A native
// Cupertino sidebar list is the same idea with the host's own
// controls; the tab bar stays the narrow-window navigation.
? Row(
children: [
_CupertinoSidebar(
selected: _selected,
onSelected: _select,
attentionCount: widget.attentionCount,
automaticallyImplyLeading: false,
middle: Text(spec?.title ?? details.label),
trailing: spec != null && spec.actions.isNotEmpty
? Row(
mainAxisSize: MainAxisSize.min,
children: spec.actions,
)
: widget.onSearch == null
? null
: CupertinoButton(
key: const ValueKey('shell.search'),
padding: EdgeInsets.zero,
onPressed: widget.onSearch,
child: const Icon(
CupertinoIcons.search,
semanticLabel: 'Search',
),
Expanded(child: _destinationStack(contents, index)),
],
)
: Column(
children: [
Expanded(child: _destinationStack(contents, index)),
CupertinoTabBar(
currentIndex: index,
onTap: (value) =>
_select(AppDestination.values[value]),
items: _items((destination) {
final item = destinationDetails(destination);
return BottomNavigationBarItem(
icon: _icon(destination, item.cupertinoIcon),
label: item.label,
);
}),
),
],
),
),
child: SafeArea(
child: wide
// The web keeps a destination rail on a wide window. A native
// Cupertino sidebar list is the same idea with the host's own
// controls; the tab bar stays the narrow-window navigation.
? Row(
children: [
_CupertinoSidebar(
selected: _selected,
onSelected: _select,
attentionCount: widget.attentionCount,
),
Expanded(child: _destinationStack(contents, index)),
],
)
: Column(
children: [
Expanded(child: _destinationStack(contents, index)),
CupertinoTabBar(
currentIndex: index,
onTap: (value) =>
_select(AppDestination.values[value]),
items: _items((destination) {
final item = destinationDetails(destination);
return BottomNavigationBarItem(
icon: _icon(destination, item.cupertinoIcon),
label: item.label,
);
}),
),
],
),
),
);
}
final spec = _bar.specFor(_selected);
return Scaffold(
appBar: AppBar(
// The open screen's own bar: its Back, title and actions.
automaticallyImplyLeading: false,
leading: spec?.onBack == null
? null
: BackButton(
key: const ValueKey('shell.back'),
onPressed: spec!.onBack,
),
title: Text(spec?.title ?? details.label),
actions: [
...?spec?.actions,
if (widget.onSearch != null && (spec?.actions.isEmpty ?? true))
IconButton(
key: const ValueKey('shell.search'),
onPressed: widget.onSearch,
tooltip: 'Search',
icon: const Icon(Icons.search),
),
],
),
body: Row(
children: [
if (wide)
NavigationRail(
selectedIndex: index,
onDestinationSelected: (value) =>
_select(AppDestination.values[value]),
labelType: NavigationRailLabelType.all,
destinations: _items((destination) {
final item = destinationDetails(destination);
return NavigationRailDestination(
icon: _icon(destination, item.icon),
label: Text(item.label),
);
}),
),
Expanded(child: _destinationStack(contents, index)),
],
),
bottomNavigationBar: wide
? null
: NavigationBar(
selectedIndex: index,
onDestinationSelected: (value) =>
_select(AppDestination.values[value]),
destinations: _items((destination) {
final item = destinationDetails(destination);
return NavigationDestination(
icon: _icon(destination, item.icon),
label: item.label,
);
}),
),
);
}
return Scaffold(
appBar: AppBar(
title: Text(details.label),
actions: [
if (widget.onSearch != null)
IconButton(
key: const ValueKey('shell.search'),
onPressed: widget.onSearch,
tooltip: 'Search',
icon: const Icon(Icons.search),
),
],
),
body: Row(
children: [
if (wide)
NavigationRail(
selectedIndex: index,
onDestinationSelected: (value) =>
_select(AppDestination.values[value]),
labelType: NavigationRailLabelType.all,
destinations: _items((destination) {
final item = destinationDetails(destination);
return NavigationRailDestination(
icon: _icon(destination, item.icon),
label: Text(item.label),
);
}),
),
Expanded(child: _destinationStack(contents, index)),
],
),
bottomNavigationBar: wide
? null
: NavigationBar(
selectedIndex: index,
onDestinationSelected: (value) =>
_select(AppDestination.values[value]),
destinations: _items((destination) {
final item = destinationDetails(destination);
return NavigationDestination(
icon: _icon(destination, item.icon),
label: item.label,
);
}),
),
);
},
},
),
);
}