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:
@@ -0,0 +1,194 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/segmented_bar_overlay.dart';
|
||||
|
||||
void _size(WidgetTester tester, double width, {double scale = 1}) {
|
||||
tester.view.physicalSize = Size(width, 700);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = scale;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
}
|
||||
|
||||
bool _ellipsised(WidgetTester tester, String text) {
|
||||
final paragraph = tester.renderObject<RenderParagraph>(find.text(text));
|
||||
return paragraph.didExceedMaxLines ||
|
||||
paragraph.size.width <
|
||||
(TextPainter(
|
||||
text: TextSpan(text: text, style: paragraph.text.style),
|
||||
textDirection: TextDirection.ltr,
|
||||
textScaler: paragraph.textScaler,
|
||||
)..layout()).width -
|
||||
0.5;
|
||||
}
|
||||
|
||||
Widget _modelAction(String model) => TextButton(
|
||||
onPressed: () {},
|
||||
child: Text(model, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
);
|
||||
|
||||
void main() {
|
||||
// The test font draws every glyph a square, so names run wider than in
|
||||
// a browser; each width takes the longest id that fits it there.
|
||||
for (final (width, model) in [
|
||||
(390.0, 'gpt-5.6-luna'),
|
||||
(560.0, 'claude-opus-5-5'),
|
||||
]) {
|
||||
testWidgets('a long model name ($model) shows whole at ${width}px', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, width);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: SegmentedBar(
|
||||
cupertino: false,
|
||||
leading: const BackButton(),
|
||||
title: 'A conversation with a rather long title indeed',
|
||||
subtitle: 'tank',
|
||||
actions: [_modelAction(model)],
|
||||
),
|
||||
body: const SizedBox.expand(),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(_ellipsised(tester, model), isFalse);
|
||||
// The title gives way first.
|
||||
expect(
|
||||
_ellipsised(tester, 'A conversation with a rather long title indeed'),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('320px at 2x text lays out without overflow', (tester) async {
|
||||
_size(tester, 320, scale: 2);
|
||||
for (final cupertino in [false, true]) {
|
||||
final bar = SegmentedBar(
|
||||
cupertino: cupertino,
|
||||
leading: SegmentedBackButton(cupertino: cupertino, onPressed: () {}),
|
||||
title: 'A long conversation title',
|
||||
subtitle: 'a-working-folder',
|
||||
subtitleIcon: Icons.folder_outlined,
|
||||
onTitlePressed: () {},
|
||||
actions: cupertino
|
||||
? [
|
||||
CupertinoButton(
|
||||
onPressed: () {},
|
||||
child: const Text(
|
||||
'gpt-5.6-luna',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
]
|
||||
: [
|
||||
_modelAction('gpt-5.6-luna'),
|
||||
IconButton(onPressed: () {}, icon: const Icon(Icons.refresh)),
|
||||
],
|
||||
);
|
||||
// A Cupertino bar over content (the conversation's own) scales its
|
||||
// text; as a navigation bar the scaffold turns scaling off.
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: SegmentedBarOverlay(
|
||||
bar: bar,
|
||||
child: const SizedBox.expand(),
|
||||
),
|
||||
),
|
||||
)
|
||||
: MaterialApp(
|
||||
home: Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: bar,
|
||||
body: const SizedBox.expand(),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(tester.takeException(), isNull, reason: 'cupertino: $cupertino');
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('taps between the pieces reach the content behind', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, 560);
|
||||
var behind = 0;
|
||||
var back = 0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: SegmentedBar(
|
||||
cupertino: false,
|
||||
leading: BackButton(onPressed: () => back++),
|
||||
title: 'Short',
|
||||
),
|
||||
body: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => behind++,
|
||||
child: const SizedBox.expand(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final barRect = tester.getRect(find.byType(SegmentedBar));
|
||||
// The empty middle of the bar, right of the short title.
|
||||
await tester.tapAt(Offset(barRect.width * 0.75, barRect.center.dy));
|
||||
expect(behind, 1);
|
||||
await tester.tap(find.byType(BackButton));
|
||||
expect(back, 1);
|
||||
expect(behind, 1);
|
||||
});
|
||||
|
||||
testWidgets('content starts below the bar at rest', (tester) async {
|
||||
_size(tester, 560);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SegmentedBarOverlay(
|
||||
bar: const SegmentedBar(cupertino: false, title: 'Overlay'),
|
||||
child: ListView(
|
||||
children: const [ListTile(title: Text('First row'))],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final bar = tester.getRect(find.byType(SegmentedBar));
|
||||
final row = tester.getRect(find.text('First row'));
|
||||
expect(row.top, greaterThanOrEqualTo(bar.bottom));
|
||||
// The list itself reaches the top, behind the bar.
|
||||
expect(tester.getRect(find.byType(ListView)).top, 0);
|
||||
});
|
||||
|
||||
testWidgets('pieces are frosted glass, solid under high contrast', (
|
||||
tester,
|
||||
) async {
|
||||
Widget app(bool highContrast) => CupertinoApp(
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(highContrast: highContrast),
|
||||
child: const CupertinoPageScaffold(
|
||||
navigationBar: SegmentedBar(cupertino: true, title: 'Glass'),
|
||||
child: SizedBox.expand(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(app(false));
|
||||
expect(find.byType(GlassPill), findsOneWidget);
|
||||
expect(find.byType(BackdropFilter), findsOneWidget);
|
||||
// The Cupertino bar draws no Material widget.
|
||||
expect(find.byType(Material), findsNothing);
|
||||
|
||||
await tester.pumpWidget(app(true));
|
||||
expect(find.byType(BackdropFilter), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user