feat(app): segmented glass top bar across the app
Extract the chat's segmented bar into lib/ui/adaptive (SegmentedBar, GlassPill, SegmentedBarOverlay) and use it for the shell bar, DetailPane and every page-level bar. Pieces are frosted glass over a fading scrim; only pills take taps. Actions keep their natural width so the title gives way before a model name. The chat transcript scrolls behind its header.
This commit is contained in:
@@ -2,6 +2,7 @@ import '../ui/motion/motion.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../ui/adaptive/segmented_bar.dart';
|
||||
import 'attention_badge.dart';
|
||||
import 'destination.dart';
|
||||
import 'shell_bar.dart';
|
||||
@@ -141,36 +142,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
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,
|
||||
),
|
||||
automaticallyImplyLeading: false,
|
||||
middle: Text(spec?.title ?? details.label),
|
||||
trailing: spec != null && spec.actions.isNotEmpty
|
||||
? MotionSwitcher(
|
||||
child: Row(
|
||||
key: ObjectKey(_bar.ownerFor(_selected)),
|
||||
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',
|
||||
),
|
||||
),
|
||||
),
|
||||
navigationBar: _segmentedBar(spec, details.label),
|
||||
child: SafeArea(
|
||||
child: wide
|
||||
// The web keeps a destination rail on a wide window. A native
|
||||
@@ -212,53 +184,32 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
}
|
||||
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,
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: _segmentedBar(spec, details.label),
|
||||
// Destinations start below the floating bar.
|
||||
body: SafeArea(
|
||||
left: false,
|
||||
right: false,
|
||||
bottom: false,
|
||||
child: 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),
|
||||
);
|
||||
}),
|
||||
),
|
||||
title: Text(spec?.title ?? details.label),
|
||||
actions: [
|
||||
if (spec != null && spec.actions.isNotEmpty)
|
||||
// A screen taking the bar over cross-fades its actions in.
|
||||
MotionSwitcher(
|
||||
child: Row(
|
||||
key: ObjectKey(_bar.ownerFor(_selected)),
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: 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)),
|
||||
],
|
||||
Expanded(child: _destinationStack(contents, index)),
|
||||
],
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: wide
|
||||
? null
|
||||
@@ -280,6 +231,57 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 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);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ 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';
|
||||
|
||||
@@ -133,40 +134,25 @@ class _DetailPaneState extends State<DetailPane> {
|
||||
// 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)) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
final bar = barless
|
||||
? null
|
||||
: SegmentedBar(
|
||||
cupertino: cupertino,
|
||||
automaticallyImplyLeading: widget.implyBack,
|
||||
title: title,
|
||||
actions: actions,
|
||||
);
|
||||
if (cupertino) {
|
||||
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),
|
||||
],
|
||||
),
|
||||
),
|
||||
navigationBar: bar,
|
||||
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),
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: bar,
|
||||
body: SafeArea(child: body),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user