Merge branch 'worktree-agent-a77fe68a62a10ce30' into integrate/notify-marked
This commit is contained in:
@@ -10,12 +10,15 @@ import 'glass_pill.dart';
|
|||||||
/// instead of becoming a full-width system bar. Used for the app's
|
/// instead of becoming a full-width system bar. Used for the app's
|
||||||
/// destinations and for every page's own tabs.
|
/// destinations and for every page's own tabs.
|
||||||
///
|
///
|
||||||
/// Placement follows the width the bar is given, live: below
|
/// At any width the pill is only as wide as its icon tabs and sits at the
|
||||||
/// [kFloatingBarWideWidth] the pill spans it minus [kFloatingBarMargin] on
|
/// trailing (right, in left-to-right text) edge, near the thumb, keeping
|
||||||
/// each side; at or above it the pill is only as wide as its tabs and sits at
|
/// [kFloatingBarMargin] from the sides and above the bottom safe area. Only
|
||||||
/// the trailing (right, in left-to-right text) edge, near the thumb. Either
|
/// the pill takes taps: the space beside it reaches the content behind.
|
||||||
/// way it keeps [kFloatingBarMargin] above the bottom safe area. Only the pill
|
///
|
||||||
/// takes taps: the space beside it reaches the content behind.
|
/// The selected tab's icon sits in a tinted circle. Each circle keeps the
|
||||||
|
/// same gap from its neighbours as from the pill's top and bottom, and the
|
||||||
|
/// outer ones the same gap from the pill's sides, so the pill's round ends
|
||||||
|
/// are concentric with them.
|
||||||
///
|
///
|
||||||
/// The tabs show icons only. Each tab's label stays its accessible name (and
|
/// The tabs show icons only. Each tab's label stays its accessible name (and
|
||||||
/// the Material tooltip), so screen readers still announce it; the icons must
|
/// the Material tooltip), so screen readers still announce it; the icons must
|
||||||
@@ -38,24 +41,44 @@ class FloatingDestinationBar extends StatelessWidget {
|
|||||||
final bool cupertino;
|
final bool cupertino;
|
||||||
|
|
||||||
/// The edge the bar floats at. At [FloatingBarEdge.top] (an open item's
|
/// The edge the bar floats at. At [FloatingBarEdge.top] (an open item's
|
||||||
/// tabs under its pane's top bar) a wide bar sits at the leading edge, in
|
/// tabs under its pane's top bar) the bar sits at the leading edge, in line
|
||||||
/// line with the bar's title, and keeps no bottom safe area.
|
/// with the bar's title, and keeps no bottom safe area.
|
||||||
final FloatingBarEdge edge;
|
final FloatingBarEdge edge;
|
||||||
final int currentIndex;
|
final int currentIndex;
|
||||||
final ValueChanged<int> onTap;
|
final ValueChanged<int> onTap;
|
||||||
final List<FloatingDestinationItem> items;
|
final List<FloatingDestinationItem> items;
|
||||||
|
|
||||||
/// Height of the Material bar inside the pill (the stock bar is 80; with
|
/// Height of the Material bar inside the pill (the stock bar is 80; with
|
||||||
/// labels hidden the icon and its indicator need less).
|
/// labels hidden the icon and its highlight need less).
|
||||||
static const double materialHeight = 56;
|
static const double materialHeight = 56;
|
||||||
|
|
||||||
/// Height of the Cupertino bar inside the pill (the stock bar's 50).
|
/// Height of the Cupertino bar inside the pill (the stock bar's 50).
|
||||||
static const double cupertinoHeight = 50;
|
static const double cupertinoHeight = 50;
|
||||||
|
|
||||||
/// Width of one icon-only tab on a wide window: a comfortable touch target
|
/// Padding between the icon (Material 24, Cupertino 26) and the edge of
|
||||||
/// around the Material indicator (64) or the Cupertino selection capsule.
|
/// its selection circle.
|
||||||
static const double materialTabWidth = 72;
|
static const double _materialRing = 8;
|
||||||
static const double cupertinoTabWidth = 64;
|
static const double _cupertinoRing = 6;
|
||||||
|
|
||||||
|
/// Diameter of the selection circle.
|
||||||
|
static const double materialHighlightSize = 24 + 2 * _materialRing;
|
||||||
|
static const double cupertinoHighlightSize = 26 + 2 * _cupertinoRing;
|
||||||
|
|
||||||
|
/// The gap between a tab's circle and the pill's top and bottom; the outer
|
||||||
|
/// circles keep the same gap from the pill's sides, and neighbours from
|
||||||
|
/// each other.
|
||||||
|
static const double materialEdgeGap =
|
||||||
|
(materialHeight - materialHighlightSize) / 2;
|
||||||
|
static const double cupertinoEdgeGap =
|
||||||
|
(cupertinoHeight - cupertinoHighlightSize) / 2;
|
||||||
|
|
||||||
|
/// Width of one tab: its circle and one edge gap (48 Material, 44
|
||||||
|
/// Cupertino: the platforms' minimum touch targets). The pill is one more
|
||||||
|
/// edge gap wider than its tabs.
|
||||||
|
static const double materialTabWidth =
|
||||||
|
materialHighlightSize + materialEdgeGap;
|
||||||
|
static const double cupertinoTabWidth =
|
||||||
|
cupertinoHighlightSize + cupertinoEdgeGap;
|
||||||
|
|
||||||
/// The side margin at [FloatingBarEdge.top], matching the top bar's own.
|
/// The side margin at [FloatingBarEdge.top], matching the top bar's own.
|
||||||
static const double topMargin = 12;
|
static const double topMargin = 12;
|
||||||
@@ -63,27 +86,18 @@ class FloatingDestinationBar extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final top = edge == FloatingBarEdge.top;
|
final top = edge == FloatingBarEdge.top;
|
||||||
final margins = 2 * (top ? topMargin : kFloatingBarMargin);
|
|
||||||
final bar = LayoutBuilder(
|
final bar = LayoutBuilder(
|
||||||
builder: (context, constraints) {
|
builder: (context, constraints) {
|
||||||
// Wide is judged on the space the bar is given, margins included,
|
final width = math.max(0.0, math.min(constraints.maxWidth, _tabsWidth));
|
||||||
// the way the shell and the pages judge their own layouts.
|
|
||||||
final available = constraints.maxWidth;
|
|
||||||
final wide = available + margins >= kFloatingBarWideWidth;
|
|
||||||
final width = wide
|
|
||||||
? math.min(available, _tabsWidth(context))
|
|
||||||
: available;
|
|
||||||
return Align(
|
return Align(
|
||||||
// As tall as the pill, so a scaffold or overlay measures the bar
|
// As tall as the pill, so a scaffold or overlay measures the bar
|
||||||
// and not the whole area it may grow into.
|
// and not the whole area it may grow into.
|
||||||
heightFactor: 1,
|
heightFactor: 1,
|
||||||
alignment: !wide
|
alignment: top
|
||||||
? Alignment.bottomCenter
|
|
||||||
: top
|
|
||||||
? AlignmentDirectional.topStart
|
? AlignmentDirectional.topStart
|
||||||
: AlignmentDirectional.bottomEnd,
|
: AlignmentDirectional.bottomEnd,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: math.max(0, width),
|
width: width,
|
||||||
// The insets are handled around the pill. The host bars pad
|
// The insets are handled around the pill. The host bars pad
|
||||||
// themselves by any media padding left over (a page's top bar,
|
// themselves by any media padding left over (a page's top bar,
|
||||||
// another floating bar below a pane), which would swell the pill.
|
// another floating bar below a pane), which would swell the pill.
|
||||||
@@ -95,9 +109,10 @@ class FloatingDestinationBar extends StatelessWidget {
|
|||||||
removeRight: true,
|
removeRight: true,
|
||||||
child: GlassPill(
|
child: GlassPill(
|
||||||
cupertino: cupertino,
|
cupertino: cupertino,
|
||||||
child: cupertino
|
child: _edgeAligned(
|
||||||
? _cupertinoBar(context)
|
width,
|
||||||
: _materialBar(context),
|
cupertino ? _cupertinoBar(context) : _materialBar(context),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -124,19 +139,48 @@ class FloatingDestinationBar extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double get _highlight =>
|
||||||
|
cupertino ? cupertinoHighlightSize : materialHighlightSize;
|
||||||
|
double get _gap => cupertino ? cupertinoEdgeGap : materialEdgeGap;
|
||||||
|
|
||||||
/// The width the icon-only tabs need side by side. Icons do not scale with
|
/// The width the icon-only tabs need side by side. Icons do not scale with
|
||||||
/// text, so the pill keeps its size at any text scale.
|
/// text, so the pill keeps its size at any text scale.
|
||||||
double _tabsWidth(BuildContext context) =>
|
double get _tabsWidth => pillWidth(cupertino: cupertino, tabs: items.length);
|
||||||
(cupertino ? cupertinoTabWidth : materialTabWidth) * items.length;
|
|
||||||
|
/// The width of a pill holding [tabs] tabs, when the space allows it.
|
||||||
|
static double pillWidth({required bool cupertino, required int tabs}) =>
|
||||||
|
cupertino
|
||||||
|
? cupertinoTabWidth * tabs + cupertinoEdgeGap
|
||||||
|
: materialTabWidth * tabs + materialEdgeGap;
|
||||||
|
|
||||||
|
/// Insets the host bar's equal tab slots so the outer circles sit the edge
|
||||||
|
/// gap from the pill's sides. A pill squeezed below its tabs' width keeps
|
||||||
|
/// that gap and narrows the gaps between neighbours instead, as long as
|
||||||
|
/// the circles still fit side by side.
|
||||||
|
Widget _edgeAligned(double width, Widget bar) {
|
||||||
|
final count = items.length;
|
||||||
|
var inset = _gap / 2;
|
||||||
|
if (count > 1) {
|
||||||
|
final slot = (width - _highlight - 2 * _gap) / (count - 1);
|
||||||
|
inset = slot >= _highlight ? (width - slot * count) / 2 : 0;
|
||||||
|
}
|
||||||
|
return Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: math.max(0, inset)),
|
||||||
|
child: bar,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _materialBar(BuildContext context) {
|
Widget _materialBar(BuildContext context) {
|
||||||
final scheme = Theme.of(context).colorScheme;
|
final scheme = Theme.of(context).colorScheme;
|
||||||
return NavigationBarTheme(
|
return NavigationBarTheme(
|
||||||
data: NavigationBarThemeData(
|
data: const NavigationBarThemeData(
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
surfaceTintColor: Colors.transparent,
|
surfaceTintColor: Colors.transparent,
|
||||||
indicatorColor: scheme.secondaryContainer,
|
// The selected icon draws its own circle (the stock indicator is a
|
||||||
|
// fixed 64x32); the stock one stays for its circular ink response.
|
||||||
|
indicatorColor: Colors.transparent,
|
||||||
|
indicatorShape: CircleBorder(),
|
||||||
height: materialHeight,
|
height: materialHeight,
|
||||||
// Icons only; the label remains each tab's accessible name and its
|
// Icons only; the label remains each tab's accessible name and its
|
||||||
// tooltip.
|
// tooltip.
|
||||||
@@ -150,7 +194,11 @@ class FloatingDestinationBar extends StatelessWidget {
|
|||||||
NavigationDestination(
|
NavigationDestination(
|
||||||
key: item.key,
|
key: item.key,
|
||||||
icon: item.icon,
|
icon: item.icon,
|
||||||
selectedIcon: item.selectedIcon ?? item.icon,
|
selectedIcon: _SelectionCircle(
|
||||||
|
color: scheme.secondaryContainer,
|
||||||
|
ring: _materialRing,
|
||||||
|
child: item.selectedIcon ?? item.icon,
|
||||||
|
),
|
||||||
label: item.label,
|
label: item.label,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -160,27 +208,27 @@ class FloatingDestinationBar extends StatelessWidget {
|
|||||||
|
|
||||||
/// The stock Cupertino bar, transparent inside the pill. Each tab shows its
|
/// The stock Cupertino bar, transparent inside the pill. Each tab shows its
|
||||||
/// icon only, named by its label for accessibility; the item's key covers
|
/// icon only, named by its label for accessibility; the item's key covers
|
||||||
/// the whole tab, and the selected tab's icon sits in a tinted capsule so
|
/// the whole tab, and the selected tab's icon sits in a tinted circle so
|
||||||
/// the selection reads at a glance, not by colour alone.
|
/// the selection reads at a glance, not by colour alone.
|
||||||
Widget _cupertinoBar(BuildContext context) {
|
Widget _cupertinoBar(BuildContext context) {
|
||||||
final active = CupertinoTheme.of(context).primaryColor;
|
final active = CupertinoTheme.of(context).primaryColor;
|
||||||
Widget tab(FloatingDestinationItem item, {required bool selected}) {
|
Widget tab(FloatingDestinationItem item, {required bool selected}) {
|
||||||
Widget icon = item.icon;
|
final icon = selected
|
||||||
if (selected) {
|
? _SelectionCircle(
|
||||||
icon = DecoratedBox(
|
color: active.withValues(alpha: 0.16),
|
||||||
decoration: ShapeDecoration(
|
ring: _cupertinoRing,
|
||||||
color: active.withValues(alpha: 0.16),
|
child: item.selectedIcon ?? item.icon,
|
||||||
shape: const StadiumBorder(),
|
)
|
||||||
),
|
: item.icon;
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 2),
|
|
||||||
child: item.selectedIcon ?? item.icon,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return KeyedSubtree(
|
return KeyedSubtree(
|
||||||
key: item.key,
|
key: item.key,
|
||||||
child: Semantics(label: item.label, child: icon),
|
child: Semantics(
|
||||||
|
label: item.label,
|
||||||
|
// The host centres the icon above a 4px bottom inset; 4 above it
|
||||||
|
// centres the icon and its circle in the whole bar, so the circle
|
||||||
|
// is as far from the pill's top as from its bottom.
|
||||||
|
child: Padding(padding: const EdgeInsets.only(top: 4), child: icon),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,6 +256,26 @@ class FloatingDestinationBar extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The selected tab's icon (and any badge on it) in a tinted circle, [ring]
|
||||||
|
/// wider than the icon on every side.
|
||||||
|
class _SelectionCircle extends StatelessWidget {
|
||||||
|
const _SelectionCircle({
|
||||||
|
required this.color,
|
||||||
|
required this.ring,
|
||||||
|
required this.child,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Color color;
|
||||||
|
final double ring;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => DecoratedBox(
|
||||||
|
decoration: ShapeDecoration(color: color, shape: const CircleBorder()),
|
||||||
|
child: Padding(padding: EdgeInsets.all(ring), child: child),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// The platform-neutral data needed by [FloatingDestinationBar].
|
/// The platform-neutral data needed by [FloatingDestinationBar].
|
||||||
class FloatingDestinationItem {
|
class FloatingDestinationItem {
|
||||||
const FloatingDestinationItem({
|
const FloatingDestinationItem({
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Floating tab bars: compact everywhere, circular selection, equal gaps
|
||||||
|
|
||||||
|
Supersedes the "Sizes" bullets of `notes/tab-bars-v2.md` and its "at 560 the
|
||||||
|
bars are full width".
|
||||||
|
|
||||||
|
- `FloatingDestinationBar` is compact at every width: sized to its tabs at
|
||||||
|
the bottom right (top start at `FloatingBarEdge.top`), on phones too. Taps
|
||||||
|
beside it reach the content.
|
||||||
|
- The selected icon sits in a tinted circle (Material 40 = 24 + 2x8 in
|
||||||
|
`secondaryContainer`, the stock indicator made transparent with a
|
||||||
|
`CircleBorder` ink; Cupertino 38 = 26 + 2x6 in the primary colour at 16%).
|
||||||
|
- One gap everywhere: circle to pill top/bottom, outer circle to pill side,
|
||||||
|
and between neighbours. Material 8 (pill 56 high, tab 48, 4 tabs = 200
|
||||||
|
wide); Cupertino 6 (pill 50, tab 44, 4 tabs = 182). The pill's round ends
|
||||||
|
are concentric with the outer circles. `FloatingDestinationBar.pillWidth`
|
||||||
|
gives the width; a squeezed pill keeps the edge gap and narrows the inner
|
||||||
|
gaps.
|
||||||
|
- Cupertino: the icon gets 4 top padding to cancel the host's 4 bottom
|
||||||
|
inset, so the circle is vertically centred.
|
||||||
|
|
||||||
|
Tests: `test/ui/adaptive/floating_bar_edge_gap_test.dart` (both hosts; 1200/4,
|
||||||
|
390/3, 390/4, 560/5, 320/5 tabs; first and last selected: side gap = top gap
|
||||||
|
= bottom gap = neighbour gap within 1px; concentric ends; phone taps beside
|
||||||
|
the bar; 320 at 2x without overflow). Phone full-width assertions in shell,
|
||||||
|
run, stage and pipeline tab tests were updated to the compact width.
|
||||||
|
|
||||||
|
Evidence: `/tmp/tab-edge-evidence/` — `{material,cupertino}-{light,dark}-
|
||||||
|
{pipelines,search}-{560,1200}.png` from `tool/floating_tabs_probe_entry.dart`
|
||||||
|
in headless Chrome (first and last tab selected).
|
||||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:pipelines_app/features/pipelines/widgets/pipeline_tabs.dart';
|
import 'package:pipelines_app/features/pipelines/widgets/pipeline_tabs.dart';
|
||||||
import 'package:pipelines_app/features/pipelines/widgets/pipeline_detail_styles.dart';
|
import 'package:pipelines_app/features/pipelines/widgets/pipeline_detail_styles.dart';
|
||||||
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@@ -66,14 +67,15 @@ void main() {
|
|||||||
findsOneWidget,
|
findsOneWidget,
|
||||||
);
|
);
|
||||||
final pill = tester.getRect(find.byType(GlassPill));
|
final pill = tester.getRect(find.byType(GlassPill));
|
||||||
if (width < 600) {
|
// Sized to its three tabs at the right edge, on a phone as when wide.
|
||||||
expect(pill.left, 16);
|
expect(pill.right, width - 16);
|
||||||
expect(pill.right, width - 16);
|
expect(
|
||||||
} else {
|
pill.width,
|
||||||
// Sized to its three tabs at the right edge.
|
FloatingDestinationBar.pillWidth(
|
||||||
expect(pill.right, width - 16);
|
cupertino: cupertino,
|
||||||
expect(pill.width, lessThan(width * 0.6));
|
tabs: PipelineDetailTab.values.length,
|
||||||
}
|
),
|
||||||
|
);
|
||||||
for (final tab in PipelineDetailTab.values) {
|
for (final tab in PipelineDetailTab.values) {
|
||||||
final rect = tester.getRect(
|
final rect = tester.getRect(
|
||||||
find.byKey(ValueKey('pipeline-detail-tab-${tab.name}')),
|
find.byKey(ValueKey('pipeline-detail-tab-${tab.name}')),
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import 'package:pipelines_app/features/runs/ui/run_more_menu.dart';
|
|||||||
import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart';
|
import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart';
|
||||||
import 'package:pipelines_app/features/runs/ui/run_detail_tab.dart';
|
import 'package:pipelines_app/features/runs/ui/run_detail_tab.dart';
|
||||||
import 'package:pipelines_app/features/runs/ui/run_detail_tab_strip.dart';
|
import 'package:pipelines_app/features/runs/ui/run_detail_tab_strip.dart';
|
||||||
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||||
|
|
||||||
import 'run_detail_graph_support.dart';
|
import 'run_detail_graph_support.dart';
|
||||||
@@ -91,8 +92,14 @@ void main() {
|
|||||||
find.descendant(of: strip, matching: find.byType(GlassPill)),
|
find.descendant(of: strip, matching: find.byType(GlassPill)),
|
||||||
);
|
);
|
||||||
final body = find.byKey(const Key('run-detail-tab-body-summary'));
|
final body = find.byKey(const Key('run-detail-tab-body-summary'));
|
||||||
// Full width minus the margins, floating above the bottom.
|
// Sized to its tabs at the right, floating above the bottom.
|
||||||
expect(pill.left, 16);
|
expect(
|
||||||
|
pill.width,
|
||||||
|
FloatingDestinationBar.pillWidth(
|
||||||
|
cupertino: platform != RunDetailTestPlatform.material,
|
||||||
|
tabs: renderedRunDetailTabs.length,
|
||||||
|
),
|
||||||
|
);
|
||||||
expect(pill.right, 390 - 16);
|
expect(pill.right, 390 - 16);
|
||||||
expect(pill.bottom, 844 - 16);
|
expect(pill.bottom, 844 - 16);
|
||||||
// The tab's content reaches the bottom edge, behind the bar.
|
// The tab's content reaches the bottom edge, behind the bar.
|
||||||
|
|||||||
@@ -245,8 +245,8 @@ void main() {
|
|||||||
final strip = tester.getRect(find.byType(RunVisitSectionStrip));
|
final strip = tester.getRect(find.byType(RunVisitSectionStrip));
|
||||||
expect(strip.bottom, size.height, reason: section.name);
|
expect(strip.bottom, size.height, reason: section.name);
|
||||||
}
|
}
|
||||||
// The floating glass bar: full width on a phone, sized to its tabs
|
// The floating glass bar: sized to its tabs at the right edge, on
|
||||||
// at the right edge of a wide page.
|
// a phone as on a wide page.
|
||||||
final pill = tester.getRect(
|
final pill = tester.getRect(
|
||||||
find.descendant(
|
find.descendant(
|
||||||
of: find.byType(RunVisitSectionStrip),
|
of: find.byType(RunVisitSectionStrip),
|
||||||
@@ -255,12 +255,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
expect(pill.right, size.width - 16);
|
expect(pill.right, size.width - 16);
|
||||||
expect(pill.bottom, size.height - 16);
|
expect(pill.bottom, size.height - 16);
|
||||||
if (size.width < 600) {
|
// Sized to its tabs at the right on every width.
|
||||||
expect(pill.left, 16);
|
expect(pill.width, lessThan(size.width * 0.7));
|
||||||
} else {
|
|
||||||
// (The test font draws every glyph a full em wide.)
|
|
||||||
expect(pill.width, lessThan(size.width * 0.7));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,16 +48,25 @@ void main() {
|
|||||||
for (final cupertino in [false, true]) {
|
for (final cupertino in [false, true]) {
|
||||||
final host = cupertino ? 'Cupertino' : 'Material';
|
final host = cupertino ? 'Cupertino' : 'Material';
|
||||||
|
|
||||||
testWidgets('$host: phone bar spans the width minus its margins', (
|
testWidgets('$host: phone bar hugs its tabs at the bottom right too, and '
|
||||||
tester,
|
'taps beside it reach the content', (tester) async {
|
||||||
) async {
|
taps = 0;
|
||||||
await setSize(tester, const Size(390, 844));
|
await setSize(tester, const Size(390, 844));
|
||||||
await tester.pumpWidget(shell(cupertino: cupertino));
|
await tester.pumpWidget(shell(cupertino: cupertino));
|
||||||
final rect = tester.getRect(pill());
|
final rect = tester.getRect(pill());
|
||||||
expect(rect.left, 16);
|
expect(
|
||||||
|
rect.width,
|
||||||
|
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
|
||||||
|
);
|
||||||
expect(rect.right, 390 - 16);
|
expect(rect.right, 390 - 16);
|
||||||
expect(rect.bottom, 844 - 16);
|
expect(rect.bottom, 844 - 16);
|
||||||
expect(find.byType(NavigationRail), findsNothing);
|
expect(find.byType(NavigationRail), findsNothing);
|
||||||
|
await tester.tapAt(Offset(rect.left - 40, rect.center.dy));
|
||||||
|
await tester.pump();
|
||||||
|
expect(taps, 1);
|
||||||
|
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Chat — Not implemented'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('$host: wide bar hugs its tabs at the right edge, content '
|
testWidgets('$host: wide bar hugs its tabs at the right edge, content '
|
||||||
@@ -69,13 +78,17 @@ void main() {
|
|||||||
expect(rect.right, 1200 - 16);
|
expect(rect.right, 1200 - 16);
|
||||||
expect(rect.bottom, 800 - 16);
|
expect(rect.bottom, 800 - 16);
|
||||||
expect(rect.width, lessThan(1200 * 0.6));
|
expect(rect.width, lessThan(1200 * 0.6));
|
||||||
// Four icon-only tabs (Settings opens from the Pipelines bar).
|
// Four icon-only tabs (Settings opens from the Pipelines bar) and one
|
||||||
|
// more edge gap, so the outer circles keep it from the sides.
|
||||||
expect(
|
expect(
|
||||||
rect.width,
|
rect.width,
|
||||||
4 *
|
4 *
|
||||||
|
(cupertino
|
||||||
|
? FloatingDestinationBar.cupertinoTabWidth
|
||||||
|
: FloatingDestinationBar.materialTabWidth) +
|
||||||
(cupertino
|
(cupertino
|
||||||
? FloatingDestinationBar.cupertinoTabWidth
|
? FloatingDestinationBar.cupertinoEdgeGap
|
||||||
: FloatingDestinationBar.materialTabWidth),
|
: FloatingDestinationBar.materialEdgeGap),
|
||||||
);
|
);
|
||||||
// No rail or sidebar: the content starts at the left edge.
|
// No rail or sidebar: the content starts at the left edge.
|
||||||
expect(find.byType(NavigationRail), findsNothing);
|
expect(find.byType(NavigationRail), findsNothing);
|
||||||
@@ -127,7 +140,11 @@ void main() {
|
|||||||
|
|
||||||
tester.view.physicalSize = const Size(390, 844);
|
tester.view.physicalSize = const Size(390, 844);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(tester.getRect(pill()).width, 390 - 32);
|
expect(
|
||||||
|
tester.getRect(pill()).width,
|
||||||
|
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
|
||||||
|
);
|
||||||
|
expect(tester.getRect(pill()).right, 390 - 16);
|
||||||
expect(tester.state(find.byType(StatefulBuilder)), same(state));
|
expect(tester.state(find.byType(StatefulBuilder)), same(state));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -186,7 +203,12 @@ void main() {
|
|||||||
await tester.pumpWidget(shell(cupertino: cupertino));
|
await tester.pumpWidget(shell(cupertino: cupertino));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
expect(tester.getRect(pill()).width, 320 - 32);
|
// Sized to its four tabs at the right, as on any width.
|
||||||
|
expect(
|
||||||
|
tester.getRect(pill()).width,
|
||||||
|
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
|
||||||
|
);
|
||||||
|
expect(tester.getRect(pill()).right, 320 - 16);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,12 @@ void main() {
|
|||||||
of: find.byType(FloatingDestinationBar),
|
of: find.byType(FloatingDestinationBar),
|
||||||
matching: find.byType(GlassPill),
|
matching: find.byType(GlassPill),
|
||||||
);
|
);
|
||||||
expect(tester.getSize(destinationPill).width, 358);
|
// Sized to its four tabs at the bottom right.
|
||||||
|
expect(
|
||||||
|
tester.getSize(destinationPill).width,
|
||||||
|
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
|
||||||
|
);
|
||||||
|
expect(tester.getRect(destinationPill).right, 390 - 16);
|
||||||
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.text('Chat — Not implemented'), findsOneWidget);
|
expect(find.text('Chat — Not implemented'), findsOneWidget);
|
||||||
|
|||||||
@@ -192,12 +192,16 @@ void main() {
|
|||||||
expect(pill.width, lessThan(1200 * 0.6));
|
expect(pill.width, lessThan(1200 * 0.6));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('$host 390: the bar spans the phone', (tester) async {
|
testWidgets('$host 390: the bar hugs its tabs at the phone\'s bottom '
|
||||||
|
'right', (tester) async {
|
||||||
await setSize(tester, const Size(390, 844));
|
await setSize(tester, const Size(390, 844));
|
||||||
await tester.pumpWidget(shell(cupertino: cupertino, split: false));
|
await tester.pumpWidget(shell(cupertino: cupertino, split: false));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
final pill = destinationPill(tester);
|
final pill = destinationPill(tester);
|
||||||
expect(pill.left, closeTo(kFloatingBarMargin, 0.5));
|
expect(
|
||||||
|
pill.width,
|
||||||
|
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
|
||||||
|
);
|
||||||
expect(pill.right, closeTo(390 - kFloatingBarMargin, 0.5));
|
expect(pill.right, closeTo(390 - kFloatingBarMargin, 0.5));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,219 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||||
|
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||||
|
|
||||||
|
/// The floating tab bar is sized to its tabs at the bottom right on every
|
||||||
|
/// width, and its selection circle keeps one gap everywhere: the first and
|
||||||
|
/// last circles sit as far from the pill's sides as from its top and bottom,
|
||||||
|
/// and neighbouring circles are that far apart too, on both hosts.
|
||||||
|
void main() {
|
||||||
|
const icons = [
|
||||||
|
Icons.account_tree_outlined,
|
||||||
|
Icons.play_circle_outline,
|
||||||
|
Icons.chat_bubble_outline,
|
||||||
|
Icons.search,
|
||||||
|
Icons.settings_outlined,
|
||||||
|
];
|
||||||
|
|
||||||
|
Key tabKey(int index) => ValueKey('tab-$index');
|
||||||
|
|
||||||
|
Widget bar({
|
||||||
|
required bool cupertino,
|
||||||
|
required int count,
|
||||||
|
required int selected,
|
||||||
|
ValueChanged<int>? onTap,
|
||||||
|
}) => FloatingDestinationBar(
|
||||||
|
cupertino: cupertino,
|
||||||
|
currentIndex: selected,
|
||||||
|
onTap: onTap ?? (_) {},
|
||||||
|
items: [
|
||||||
|
for (var index = 0; index < count; index += 1)
|
||||||
|
FloatingDestinationItem(
|
||||||
|
key: tabKey(index),
|
||||||
|
icon: Icon(icons[index]),
|
||||||
|
label: 'Tab $index',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
Future<void> pump(
|
||||||
|
WidgetTester tester, {
|
||||||
|
required bool cupertino,
|
||||||
|
required Size size,
|
||||||
|
required Widget child,
|
||||||
|
double textScale = 1,
|
||||||
|
}) async {
|
||||||
|
tester.view.physicalSize = size;
|
||||||
|
tester.view.devicePixelRatio = 1;
|
||||||
|
addTearDown(tester.view.reset);
|
||||||
|
final body = MediaQuery(
|
||||||
|
data: MediaQueryData(
|
||||||
|
size: size,
|
||||||
|
textScaler: TextScaler.linear(textScale),
|
||||||
|
),
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
cupertino
|
||||||
|
? CupertinoApp(home: CupertinoPageScaffold(child: body))
|
||||||
|
: MaterialApp(home: Scaffold(body: body)),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect circle(WidgetTester tester, int index) => tester.getRect(
|
||||||
|
find
|
||||||
|
.descendant(
|
||||||
|
of: find.byKey(tabKey(index)),
|
||||||
|
matching: find.byWidgetPredicate(
|
||||||
|
(widget) =>
|
||||||
|
widget is DecoratedBox &&
|
||||||
|
widget.decoration is ShapeDecoration &&
|
||||||
|
(widget.decoration as ShapeDecoration).shape is CircleBorder,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.first,
|
||||||
|
);
|
||||||
|
|
||||||
|
Rect pill(WidgetTester tester) => tester.getRect(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byType(FloatingDestinationBar),
|
||||||
|
matching: find.byType(GlassPill),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final placements = [
|
||||||
|
(name: 'wide 1200, 4 tabs', size: const Size(1200, 800), count: 4),
|
||||||
|
(name: 'phone 390, 3 tabs', size: const Size(390, 844), count: 3),
|
||||||
|
(name: 'phone 390, 4 tabs', size: const Size(390, 844), count: 4),
|
||||||
|
(name: 'phone 560, 5 tabs', size: const Size(560, 844), count: 5),
|
||||||
|
(name: 'phone 320, 5 tabs', size: const Size(320, 640), count: 5),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (final cupertino in [false, true]) {
|
||||||
|
final host = cupertino ? 'Cupertino' : 'Material';
|
||||||
|
for (final placement in placements) {
|
||||||
|
testWidgets('$host ${placement.name}: compact at the bottom right; the '
|
||||||
|
'outer circles keep the top gap from the sides and neighbours', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final count = placement.count;
|
||||||
|
final size = placement.size;
|
||||||
|
final centres = <double>[];
|
||||||
|
for (final selected in [0, count - 1]) {
|
||||||
|
await pump(
|
||||||
|
tester,
|
||||||
|
cupertino: cupertino,
|
||||||
|
size: size,
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.bottomCenter,
|
||||||
|
child: bar(
|
||||||
|
cupertino: cupertino,
|
||||||
|
count: count,
|
||||||
|
selected: selected,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final box = pill(tester);
|
||||||
|
expect(box.right, size.width - 16);
|
||||||
|
expect(box.bottom, size.height - 16);
|
||||||
|
final mark = circle(tester, selected);
|
||||||
|
expect(mark.width, mark.height);
|
||||||
|
final top = mark.top - box.top;
|
||||||
|
expect(box.bottom - mark.bottom, moreOrLessEquals(top, epsilon: 1));
|
||||||
|
final side = selected == 0
|
||||||
|
? mark.left - box.left
|
||||||
|
: box.right - mark.right;
|
||||||
|
expect(
|
||||||
|
side,
|
||||||
|
moreOrLessEquals(top, epsilon: 1),
|
||||||
|
reason: 'side gap $side vs top gap $top',
|
||||||
|
);
|
||||||
|
// The pill's round end is concentric with the outer circle.
|
||||||
|
expect(box.height / 2, moreOrLessEquals(top + mark.width / 2));
|
||||||
|
}
|
||||||
|
// Unselected icons sit where their circle would: neighbours are
|
||||||
|
// evenly spaced, one edge gap apart.
|
||||||
|
for (var index = 0; index < count; index += 1) {
|
||||||
|
centres.add(
|
||||||
|
tester
|
||||||
|
.getCenter(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byKey(tabKey(index)),
|
||||||
|
matching: find.byIcon(icons[index]),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.dx,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final last = circle(tester, count - 1);
|
||||||
|
final gap = last.top - pill(tester).top;
|
||||||
|
for (var index = 1; index < count; index += 1) {
|
||||||
|
expect(
|
||||||
|
centres[index] - centres[index - 1] - last.width,
|
||||||
|
moreOrLessEquals(gap, epsilon: 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect(last.center.dx, moreOrLessEquals(centres.last, epsilon: 1));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets('$host phone: taps beside the compact bar reach the content, '
|
||||||
|
'taps on it the tabs', (tester) async {
|
||||||
|
final tapped = <int>[];
|
||||||
|
var content = 0;
|
||||||
|
await pump(
|
||||||
|
tester,
|
||||||
|
cupertino: cupertino,
|
||||||
|
size: const Size(390, 844),
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Positioned.fill(
|
||||||
|
child: GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: () => content++,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.bottomCenter,
|
||||||
|
child: bar(
|
||||||
|
cupertino: cupertino,
|
||||||
|
count: 3,
|
||||||
|
selected: 1,
|
||||||
|
onTap: tapped.add,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final box = pill(tester);
|
||||||
|
expect(box.width, lessThan(390 / 2));
|
||||||
|
await tester.tapAt(Offset(box.left - 40, box.center.dy));
|
||||||
|
await tester.tapAt(box.centerLeft + const Offset(12, 0));
|
||||||
|
await tester.tapAt(box.centerRight - const Offset(12, 0));
|
||||||
|
await tester.pump();
|
||||||
|
expect(content, 1);
|
||||||
|
expect(tapped, [0, 2]);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('$host: 5 tabs at 320 with 2x text do not overflow', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pump(
|
||||||
|
tester,
|
||||||
|
cupertino: cupertino,
|
||||||
|
size: const Size(320, 640),
|
||||||
|
textScale: 2,
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.bottomCenter,
|
||||||
|
child: bar(cupertino: cupertino, count: 5, selected: 4),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
expect(pill(tester).right, 320 - 16);
|
||||||
|
expect(pill(tester).left, greaterThanOrEqualTo(16));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user