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:
@@ -1,10 +1,11 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/adaptive/segmented_bar.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
|
||||
/// The open conversation's bar: separate rounded pieces on the page's own
|
||||
/// background above the transcript, instead of one solid app bar.
|
||||
/// The open conversation's bar: the app's [SegmentedBar] above the
|
||||
/// transcript.
|
||||
///
|
||||
/// From the leading edge: a round Back (only where the page can go back), a
|
||||
/// pill with the conversation's title and folder that opens the chat's
|
||||
@@ -37,206 +38,26 @@ class ChatThreadHeader extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final background = cupertino
|
||||
? CupertinoTheme.of(context).scaffoldBackgroundColor
|
||||
: Theme.of(context).colorScheme.surface;
|
||||
return ColoredBox(
|
||||
color: background,
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(12, 8, 12, 16),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) => Row(
|
||||
children: [
|
||||
if (showBack) ...[
|
||||
_ChatHeaderPill(
|
||||
circle: true,
|
||||
child: _BackControl(
|
||||
cupertino: cupertino,
|
||||
onPressed: onBack,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: _TitlePill(
|
||||
title: title,
|
||||
folder: folder,
|
||||
cupertino: cupertino,
|
||||
onPressed: onInfo,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (controls.isNotEmpty) ...[
|
||||
const SizedBox(width: 8),
|
||||
// The controls keep to the trailing edge and at most about
|
||||
// half the bar, so the title always has room; each control
|
||||
// ellipsises its own label, the model's taking the larger share.
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: constraints.maxWidth * 0.45,
|
||||
),
|
||||
child: _ChatHeaderPill(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(flex: 3, child: controls.first),
|
||||
for (final control in controls.skip(1))
|
||||
Flexible(flex: 2, child: control),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// One rounded, filled piece of the bar in the host's raised surface role.
|
||||
class _ChatHeaderPill extends StatelessWidget {
|
||||
const _ChatHeaderPill({required this.child, this.circle = false});
|
||||
|
||||
final Widget child;
|
||||
final bool circle;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final fill = cupertino
|
||||
? CupertinoColors.systemGrey6.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
final shape = circle
|
||||
? const CircleBorder()
|
||||
: const StadiumBorder() as ShapeBorder;
|
||||
if (cupertino) {
|
||||
return ClipPath(
|
||||
clipper: ShapeBorderClipper(shape: shape),
|
||||
child: ColoredBox(color: fill, child: child),
|
||||
);
|
||||
}
|
||||
return Material(
|
||||
color: fill,
|
||||
shape: shape,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The platform's own Back control, so it reads and behaves as every other
|
||||
/// page's Back; its key and the conversation's destination wording stay.
|
||||
class _BackControl extends StatelessWidget {
|
||||
const _BackControl({required this.cupertino, required this.onPressed});
|
||||
|
||||
final bool cupertino;
|
||||
final VoidCallback? onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => KeyedSubtree(
|
||||
key: const Key('chat-back'),
|
||||
child: cupertino
|
||||
? CupertinoNavigationBarBackButton(onPressed: onPressed)
|
||||
: BackButton(onPressed: onPressed),
|
||||
);
|
||||
}
|
||||
|
||||
/// The title and its folder in one pill; pressing it opens the chat's
|
||||
/// information.
|
||||
class _TitlePill extends StatelessWidget {
|
||||
const _TitlePill({
|
||||
required this.title,
|
||||
required this.folder,
|
||||
required this.cupertino,
|
||||
required this.onPressed,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String folder;
|
||||
final bool cupertino;
|
||||
final VoidCallback onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final TextStyle? titleStyle;
|
||||
final TextStyle? folderStyle;
|
||||
if (cupertino) {
|
||||
final text = CupertinoTheme.of(context).textTheme;
|
||||
titleStyle = text.textStyle.copyWith(fontWeight: FontWeight.w600);
|
||||
folderStyle = text.tabLabelTextStyle.copyWith(
|
||||
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
||||
);
|
||||
} else {
|
||||
final theme = Theme.of(context);
|
||||
titleStyle = theme.textTheme.titleSmall;
|
||||
folderStyle = theme.textTheme.labelSmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
);
|
||||
}
|
||||
final content = Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title.isEmpty ? 'Chat' : title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: titleStyle,
|
||||
),
|
||||
if (folder.isNotEmpty)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
cupertino ? CupertinoIcons.folder : Icons.folder_outlined,
|
||||
size: folderStyle?.fontSize,
|
||||
color: folderStyle?.color,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Flexible(
|
||||
child: Text(
|
||||
folder,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: folderStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return _ChatHeaderPill(
|
||||
child: Semantics(
|
||||
button: true,
|
||||
label: 'Chat information',
|
||||
child: cupertino
|
||||
? CupertinoButton(
|
||||
key: const Key('chat-info'),
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: Size.zero,
|
||||
onPressed: onPressed,
|
||||
child: DefaultTextStyle.merge(
|
||||
style: titleStyle,
|
||||
child: content,
|
||||
),
|
||||
)
|
||||
: InkWell(
|
||||
key: const Key('chat-info'),
|
||||
onTap: onPressed,
|
||||
child: content,
|
||||
),
|
||||
),
|
||||
return SegmentedBar(
|
||||
cupertino: cupertino,
|
||||
automaticallyImplyLeading: false,
|
||||
// The platform's own Back, so it reads and behaves as every other
|
||||
// page's Back; its key stays for finders.
|
||||
leading: showBack
|
||||
? SegmentedBackButton(
|
||||
key: const Key('chat-back'),
|
||||
cupertino: cupertino,
|
||||
onPressed: onBack,
|
||||
)
|
||||
: null,
|
||||
title: title.isEmpty ? 'Chat' : title,
|
||||
subtitle: folder,
|
||||
subtitleIcon: cupertino ? CupertinoIcons.folder : Icons.folder_outlined,
|
||||
onTitlePressed: onInfo,
|
||||
titleSemanticLabel: 'Chat information',
|
||||
titleKey: const Key('chat-info'),
|
||||
actions: controls,
|
||||
bottomPadding: 16,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user