Merge: tabs as separate round glass buttons
This commit is contained in:
@@ -1,37 +1,32 @@
|
|||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
import 'dart:ui' show SemanticsRole;
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'floating_bar_layout.dart';
|
import 'floating_bar_layout.dart';
|
||||||
|
import 'floating_tab_button.dart';
|
||||||
import 'floating_tab_motion.dart';
|
import 'floating_tab_motion.dart';
|
||||||
import 'glass_pill.dart';
|
|
||||||
|
|
||||||
/// A tab bar which floats above the bottom edge in a frosted [GlassPill]
|
/// A tab bar which floats above the bottom edge as a row of separate round
|
||||||
/// instead of becoming a full-width system bar. Used for the app's
|
/// frosted [GlassPill] buttons, one per tab, instead of a full-width system
|
||||||
/// destinations and for every page's own tabs.
|
/// bar. Used for the app's destinations and for every page's own tabs.
|
||||||
///
|
///
|
||||||
/// At any width the pill is only as wide as its icon tabs and sits at the
|
/// The row is only as wide as its buttons and sits at the trailing (right,
|
||||||
/// trailing (right, in left-to-right text) edge, near the thumb, keeping
|
/// in left-to-right text) edge, near the thumb, keeping [kFloatingBarMargin]
|
||||||
/// [kFloatingBarMargin] from the sides and above the bottom safe area. Only
|
/// from the sides and above the bottom safe area. Only the buttons take
|
||||||
/// the pill takes taps: the space beside it reaches the content behind.
|
/// taps: the gaps between and beside them reach the content behind. A row
|
||||||
|
/// squeezed below its natural width narrows its gaps, then scales down.
|
||||||
///
|
///
|
||||||
/// One tinted circle sits behind the selected tab's icon and glides to a
|
/// The selected button is filled with the host's selection tint, which
|
||||||
/// newly selected tab. At rest it keeps the same gap from its neighbours' slots
|
/// cross-fades when the selection moves, and its icon bounces briefly. Each
|
||||||
/// as from the pill's top and bottom, and at the outer tabs the same gap from
|
/// button pops in on its own, staggered, when the bar appears or its set of
|
||||||
/// the pill's sides, so the pill's round ends are concentric with it.
|
/// tabs changes, never when only the selection does.
|
||||||
///
|
///
|
||||||
/// The tabs pop in when the bar appears or its set of tabs changes, never
|
/// The buttons show icons only. Each tab's label stays its accessible name
|
||||||
/// when only the selection does.
|
/// (and the Material tooltip), announced as a selectable tab with "tab n of
|
||||||
///
|
/// m" the way the platform navigation controls announce theirs (see
|
||||||
/// The tabs show icons only. Each tab's label stays its accessible name (and
|
/// [FloatingTabButton]); the icons must be distinct within a bar. The
|
||||||
/// the Material tooltip), so screen readers still announce it; the icons must
|
/// Cupertino path builds no Material widget.
|
||||||
/// be distinct within a bar.
|
|
||||||
///
|
|
||||||
/// The controls inside remain the platform navigation controls (Material
|
|
||||||
/// [NavigationBar], Cupertino [CupertinoTabBar]), so tab semantics (selected
|
|
||||||
/// state, "tab n of m") come from the host. The Cupertino path builds no
|
|
||||||
/// Material widget.
|
|
||||||
class FloatingDestinationBar extends StatefulWidget {
|
class FloatingDestinationBar extends StatefulWidget {
|
||||||
const FloatingDestinationBar({
|
const FloatingDestinationBar({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -52,64 +47,34 @@ class FloatingDestinationBar extends StatefulWidget {
|
|||||||
final ValueChanged<int> onTap;
|
final ValueChanged<int> onTap;
|
||||||
final List<FloatingDestinationItem> items;
|
final List<FloatingDestinationItem> items;
|
||||||
|
|
||||||
/// The icon sizes used by the two host navigation controls.
|
/// The icon size inside each button, as in the host navigation controls.
|
||||||
static const double materialIconSize = 28;
|
static const double materialIconSize = 28;
|
||||||
static const double cupertinoIconSize = 30;
|
static const double cupertinoIconSize = 30;
|
||||||
|
|
||||||
/// Padding between each icon and the edge of its selection circle.
|
/// The diameter of each tab button, which is also the bar's height.
|
||||||
static const double _materialRing = 8;
|
static const double materialButtonSize = 52;
|
||||||
static const double _cupertinoRing = 6;
|
static const double cupertinoButtonSize = 50;
|
||||||
|
|
||||||
/// The gap between a circle and the pill's nearest edge or neighbour.
|
/// The gap between neighbouring buttons.
|
||||||
/// Keeping these as the source constants makes the bar grow with the icons.
|
static const double materialButtonGap = 12;
|
||||||
static const double _materialEdgeGap = 8;
|
static const double cupertinoButtonGap = 10;
|
||||||
static const double _cupertinoEdgeGap = 6;
|
|
||||||
|
|
||||||
/// Diameter of the selection circle.
|
|
||||||
static const double materialHighlightSize =
|
|
||||||
materialIconSize + 2 * _materialRing;
|
|
||||||
static const double cupertinoHighlightSize =
|
|
||||||
cupertinoIconSize + 2 * _cupertinoRing;
|
|
||||||
|
|
||||||
/// Height of the host bar, derived from its circle and the equal edge gaps.
|
|
||||||
static const double materialHeight =
|
|
||||||
materialHighlightSize + 2 * _materialEdgeGap;
|
|
||||||
static const double cupertinoHeight =
|
|
||||||
cupertinoHighlightSize + 2 * _cupertinoEdgeGap;
|
|
||||||
|
|
||||||
/// 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 = _materialEdgeGap;
|
|
||||||
static const double cupertinoEdgeGap = _cupertinoEdgeGap;
|
|
||||||
|
|
||||||
/// The additional breathing room between neighbouring selection circles.
|
|
||||||
static const double materialNeighbourGap = 15;
|
|
||||||
static const double cupertinoNeighbourGap = 13;
|
|
||||||
|
|
||||||
/// Width of one equal native tab slot at the requested neighbour spacing.
|
|
||||||
static const double materialTabWidth =
|
|
||||||
materialHighlightSize + materialNeighbourGap;
|
|
||||||
static const double cupertinoTabWidth =
|
|
||||||
cupertinoHighlightSize + cupertinoNeighbourGap;
|
|
||||||
|
|
||||||
/// 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;
|
||||||
|
|
||||||
/// The selection highlight inside each bar, for tests.
|
/// The row of buttons inside each bar, for tests and measurement.
|
||||||
static const Key highlightKey = ValueKey(
|
static const Key rowKey = ValueKey('floating-destination-bar.row');
|
||||||
'floating-destination-bar.highlight',
|
|
||||||
);
|
|
||||||
|
|
||||||
/// The width of a pill holding [tabs] tabs, when the space allows it.
|
static double buttonSize({required bool cupertino}) =>
|
||||||
static double pillWidth({required bool cupertino, required int tabs}) =>
|
cupertino ? cupertinoButtonSize : materialButtonSize;
|
||||||
cupertino
|
|
||||||
? cupertinoHighlightSize * tabs +
|
static double buttonGap({required bool cupertino}) =>
|
||||||
2 * cupertinoEdgeGap +
|
cupertino ? cupertinoButtonGap : materialButtonGap;
|
||||||
math.max(0, tabs - 1) * cupertinoNeighbourGap
|
|
||||||
: materialHighlightSize * tabs +
|
/// The width of a row of [tabs] buttons, when the space allows it.
|
||||||
2 * materialEdgeGap +
|
static double rowWidth({required bool cupertino, required int tabs}) =>
|
||||||
math.max(0, tabs - 1) * materialNeighbourGap;
|
buttonSize(cupertino: cupertino) * tabs +
|
||||||
|
buttonGap(cupertino: cupertino) * math.max(0, tabs - 1);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<FloatingDestinationBar> createState() => _FloatingDestinationBarState();
|
State<FloatingDestinationBar> createState() => _FloatingDestinationBarState();
|
||||||
@@ -118,6 +83,7 @@ class FloatingDestinationBar extends StatefulWidget {
|
|||||||
class _FloatingDestinationBarState extends State<FloatingDestinationBar>
|
class _FloatingDestinationBarState extends State<FloatingDestinationBar>
|
||||||
with TickerProviderStateMixin {
|
with TickerProviderStateMixin {
|
||||||
late final FloatingTabMotion _motion = FloatingTabMotion(this);
|
late final FloatingTabMotion _motion = FloatingTabMotion(this);
|
||||||
|
final _backdrop = BackdropKey();
|
||||||
bool _entered = false;
|
bool _entered = false;
|
||||||
|
|
||||||
bool get cupertino => widget.cupertino;
|
bool get cupertino => widget.cupertino;
|
||||||
@@ -136,8 +102,7 @@ class _FloatingDestinationBarState extends State<FloatingDestinationBar>
|
|||||||
void didUpdateWidget(FloatingDestinationBar oldWidget) {
|
void didUpdateWidget(FloatingDestinationBar oldWidget) {
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
if (_tabSetIdentity(oldWidget.items) != _tabSetIdentity(items)) {
|
if (_tabSetIdentity(oldWidget.items) != _tabSetIdentity(items)) {
|
||||||
// New tabs (a run's page tabs appearing): they pop in, and the
|
// New tabs (a run's page tabs appearing): they pop in.
|
||||||
// highlight starts on the selected one.
|
|
||||||
_motion.enter(context, count: items.length, selected: currentIndex);
|
_motion.enter(context, count: items.length, selected: currentIndex);
|
||||||
} else if (oldWidget.currentIndex != currentIndex) {
|
} else if (oldWidget.currentIndex != currentIndex) {
|
||||||
_motion.select(context, currentIndex);
|
_motion.select(context, currentIndex);
|
||||||
@@ -153,44 +118,21 @@ class _FloatingDestinationBarState extends State<FloatingDestinationBar>
|
|||||||
static String _tabSetIdentity(List<FloatingDestinationItem> items) =>
|
static String _tabSetIdentity(List<FloatingDestinationItem> items) =>
|
||||||
items.map((item) => '${item.key ?? item.label}:${item.label}').join('|');
|
items.map((item) => '${item.key ?? item.label}:${item.label}').join('|');
|
||||||
|
|
||||||
|
double get _size => FloatingDestinationBar.buttonSize(cupertino: cupertino);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final top = widget.edge == FloatingBarEdge.top;
|
final top = widget.edge == FloatingBarEdge.top;
|
||||||
final bar = LayoutBuilder(
|
final bar = LayoutBuilder(
|
||||||
builder: (context, constraints) {
|
builder: (context, constraints) => Align(
|
||||||
final width = math.max(0.0, math.min(constraints.maxWidth, _tabsWidth));
|
// As tall as the row, so a scaffold or overlay measures the bar and
|
||||||
return Align(
|
// not the whole area it may grow into.
|
||||||
// As tall as the pill, so a scaffold or overlay measures the bar
|
heightFactor: 1,
|
||||||
// and not the whole area it may grow into.
|
alignment: top
|
||||||
heightFactor: 1,
|
? AlignmentDirectional.topStart
|
||||||
alignment: top
|
: AlignmentDirectional.bottomEnd,
|
||||||
? AlignmentDirectional.topStart
|
child: _row(context, constraints.maxWidth),
|
||||||
: AlignmentDirectional.bottomEnd,
|
),
|
||||||
child: SizedBox(
|
|
||||||
width: width,
|
|
||||||
// The insets are handled around the pill. The host bars pad
|
|
||||||
// themselves by any media padding left over (a page's top bar,
|
|
||||||
// another floating bar below a pane), which would swell the pill.
|
|
||||||
child: MediaQuery.removePadding(
|
|
||||||
context: context,
|
|
||||||
removeTop: true,
|
|
||||||
removeBottom: true,
|
|
||||||
removeLeft: true,
|
|
||||||
removeRight: true,
|
|
||||||
child: GlassPill(
|
|
||||||
cupertino: cupertino,
|
|
||||||
child: _edgeAligned(
|
|
||||||
context,
|
|
||||||
width,
|
|
||||||
cupertino
|
|
||||||
? _cupertinoBar(context, _slot(width))
|
|
||||||
: _materialBar(context),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
if (top) {
|
if (top) {
|
||||||
// Under a top bar: no safe area to keep clear of, only the gap to the
|
// Under a top bar: no safe area to keep clear of, only the gap to the
|
||||||
@@ -217,207 +159,71 @@ class _FloatingDestinationBarState extends State<FloatingDestinationBar>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
double get _highlight => cupertino
|
/// The gap between neighbouring buttons in [width]: the named one, or less
|
||||||
? FloatingDestinationBar.cupertinoHighlightSize
|
/// in a row squeezed below its natural width.
|
||||||
: FloatingDestinationBar.materialHighlightSize;
|
double _gap(double width) {
|
||||||
double get _gap => cupertino
|
final gap = FloatingDestinationBar.buttonGap(cupertino: cupertino);
|
||||||
? FloatingDestinationBar.cupertinoEdgeGap
|
|
||||||
: FloatingDestinationBar.materialEdgeGap;
|
|
||||||
double get _neighbourGap => cupertino
|
|
||||||
? FloatingDestinationBar.cupertinoNeighbourGap
|
|
||||||
: FloatingDestinationBar.materialNeighbourGap;
|
|
||||||
|
|
||||||
/// 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.
|
|
||||||
double get _tabsWidth => FloatingDestinationBar.pillWidth(
|
|
||||||
cupertino: cupertino,
|
|
||||||
tabs: items.length,
|
|
||||||
);
|
|
||||||
|
|
||||||
/// The gap between neighbouring circles in a pill [width] wide: the named
|
|
||||||
/// one, or less in a pill squeezed below its tabs' width.
|
|
||||||
double _neighbour(double width) {
|
|
||||||
final count = items.length;
|
final count = items.length;
|
||||||
if (count < 2) return _neighbourGap;
|
if (count < 2 || !width.isFinite) return gap;
|
||||||
final available = math.max(0.0, width - 2 * _gap - count * _highlight);
|
return (width - count * _size).clamp(0.0, gap * (count - 1)) / (count - 1);
|
||||||
return math.min(_neighbourGap, available / (count - 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The width of each equal tab slot, which is also the distance between
|
Widget _row(BuildContext context, double width) {
|
||||||
/// neighbouring circles' centres.
|
final gap = _gap(width);
|
||||||
double _slot(double width) => _highlight + math.max(0, _neighbour(width));
|
Widget row = Row(
|
||||||
|
key: FloatingDestinationBar.rowKey,
|
||||||
bool get _hasSelection => currentIndex >= 0 && currentIndex < items.length;
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
/// Insets the host bar's equal tab slots so the outer circles sit the edge
|
for (var index = 0; index < items.length; index += 1) ...[
|
||||||
/// gap from the pill's sides. A pill squeezed below its tabs' width keeps
|
if (index > 0) SizedBox(width: gap),
|
||||||
/// that gap and narrows the gaps between neighbours instead, as long as
|
_button(context, index),
|
||||||
/// the circles still fit side by side. The Material highlight is laid over
|
|
||||||
/// the first slot, behind the host bar.
|
|
||||||
Widget _edgeAligned(BuildContext context, double width, Widget bar) {
|
|
||||||
final count = items.length;
|
|
||||||
if (count == 0) return bar;
|
|
||||||
// The native bars use equal-width slots. Let their slot centers be the
|
|
||||||
// desired circle centers, and translate the slots by half the difference
|
|
||||||
// between the outer and neighbour gaps. The pill clips the harmless
|
|
||||||
// overflow of the native slot backgrounds, while the circles remain
|
|
||||||
// exactly edge-aligned.
|
|
||||||
final slot = _slot(width);
|
|
||||||
final offset = _gap - _neighbour(width) / 2;
|
|
||||||
return ClipRect(
|
|
||||||
child: SizedBox(
|
|
||||||
width: width,
|
|
||||||
height: cupertino
|
|
||||||
? FloatingDestinationBar.cupertinoHeight
|
|
||||||
: FloatingDestinationBar.materialHeight,
|
|
||||||
child: OverflowBox(
|
|
||||||
alignment: AlignmentDirectional.topStart,
|
|
||||||
minWidth: 0,
|
|
||||||
maxWidth: double.infinity,
|
|
||||||
child: Transform.translate(
|
|
||||||
offset: Offset(offset, 0),
|
|
||||||
child: SizedBox(
|
|
||||||
width: slot * count,
|
|
||||||
child: Stack(
|
|
||||||
fit: StackFit.expand,
|
|
||||||
children: [
|
|
||||||
if (!cupertino && _hasSelection)
|
|
||||||
PositionedDirectional(
|
|
||||||
start: 0,
|
|
||||||
top: 0,
|
|
||||||
bottom: 0,
|
|
||||||
width: slot,
|
|
||||||
child: _highlightFor(context, slot),
|
|
||||||
),
|
|
||||||
bar,
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The bar's one selection highlight, laid out over tab 0.
|
|
||||||
Widget _highlightFor(BuildContext context, double slot) =>
|
|
||||||
FloatingTabHighlight(
|
|
||||||
key: FloatingDestinationBar.highlightKey,
|
|
||||||
motion: _motion,
|
|
||||||
slot: slot,
|
|
||||||
size: _highlight,
|
|
||||||
color: cupertino
|
|
||||||
? CupertinoTheme.of(context).primaryColor.withValues(alpha: 0.16)
|
|
||||||
: Theme.of(context).colorScheme.secondaryContainer,
|
|
||||||
);
|
|
||||||
|
|
||||||
Widget _materialBar(BuildContext context) {
|
|
||||||
return NavigationBarTheme(
|
|
||||||
data: const NavigationBarThemeData(
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
elevation: 0,
|
|
||||||
surfaceTintColor: Colors.transparent,
|
|
||||||
// The bar draws one gliding highlight behind the icons (the stock
|
|
||||||
// indicator is a fixed 64x32 that jumps); the stock one stays for
|
|
||||||
// its circular ink response.
|
|
||||||
indicatorColor: Colors.transparent,
|
|
||||||
indicatorShape: CircleBorder(),
|
|
||||||
height: FloatingDestinationBar.materialHeight,
|
|
||||||
iconTheme: WidgetStatePropertyAll(
|
|
||||||
IconThemeData(size: FloatingDestinationBar.materialIconSize),
|
|
||||||
),
|
|
||||||
// Icons only; the label remains each tab's accessible name and its
|
|
||||||
// tooltip.
|
|
||||||
labelBehavior: NavigationDestinationLabelBehavior.alwaysHide,
|
|
||||||
),
|
|
||||||
child: NavigationBar(
|
|
||||||
selectedIndex: currentIndex,
|
|
||||||
onDestinationSelected: widget.onTap,
|
|
||||||
destinations: [
|
|
||||||
for (var index = 0; index < items.length; index += 1)
|
|
||||||
NavigationDestination(
|
|
||||||
key: items[index].key,
|
|
||||||
icon: _icon(items[index].icon, index),
|
|
||||||
selectedIcon: _icon(
|
|
||||||
items[index].selectedIcon ?? items[index].icon,
|
|
||||||
index,
|
|
||||||
),
|
|
||||||
label: items[index].label,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
],
|
||||||
);
|
);
|
||||||
}
|
// Narrower than the buttons themselves: the whole row shrinks.
|
||||||
|
if (width.isFinite && width < items.length * _size) {
|
||||||
/// The stock Cupertino bar, transparent inside the pill. Each tab shows its
|
row = SizedBox(
|
||||||
/// icon only, named by its label for accessibility; the item's key covers
|
width: math.max(0.0, width),
|
||||||
/// the whole tab, and the highlight behind the selected icon makes the
|
height: _size,
|
||||||
/// selection read at a glance, not by colour alone.
|
child: FittedBox(fit: BoxFit.scaleDown, child: row),
|
||||||
///
|
|
||||||
/// The host blurs whatever is behind its translucent background, so the
|
|
||||||
/// highlight is painted from inside tab 0, under the icons but above the
|
|
||||||
/// blur.
|
|
||||||
Widget _cupertinoBar(BuildContext context, double slot) {
|
|
||||||
Widget tab(
|
|
||||||
FloatingDestinationItem item, {
|
|
||||||
required bool selected,
|
|
||||||
required int index,
|
|
||||||
}) {
|
|
||||||
final icon = _icon(
|
|
||||||
selected ? item.selectedIcon ?? item.icon : item.icon,
|
|
||||||
index,
|
|
||||||
);
|
|
||||||
return KeyedSubtree(
|
|
||||||
key: item.key,
|
|
||||||
child: Semantics(
|
|
||||||
label: item.label,
|
|
||||||
// The host centres the icon above a 4px bottom inset; 4 above it
|
|
||||||
// centres the icon and its highlight in the whole bar, so the
|
|
||||||
// highlight is as far from the pill's top as from its bottom.
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 4),
|
|
||||||
child: index == 0 && _hasSelection
|
|
||||||
? Stack(
|
|
||||||
clipBehavior: Clip.none,
|
|
||||||
alignment: Alignment.center,
|
|
||||||
children: [
|
|
||||||
Positioned.fill(child: _highlightFor(context, slot)),
|
|
||||||
icon,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
: icon,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// One tab bar, its buttons the tabs. The buttons share one read of the
|
||||||
|
// content behind them for their blurs where the engine supports it.
|
||||||
|
row = Semantics(
|
||||||
|
role: SemanticsRole.tabBar,
|
||||||
|
container: true,
|
||||||
|
explicitChildNodes: true,
|
||||||
|
child: BackdropGroup(backdropKey: _backdrop, child: row),
|
||||||
|
);
|
||||||
|
// The bar does not scale with text (its icons do not either); a badge
|
||||||
|
// count keeps its size.
|
||||||
|
return cupertino ? MediaQuery.withNoTextScaling(child: row) : row;
|
||||||
|
}
|
||||||
|
|
||||||
// The tab bar does not scale its text on iOS either; its height is fixed.
|
Widget _button(BuildContext context, int index) {
|
||||||
return MediaQuery.withNoTextScaling(
|
final item = items[index];
|
||||||
child: CupertinoTabBar(
|
final selected = index == currentIndex;
|
||||||
backgroundColor: CupertinoColors.transparent,
|
return FloatingTabEntrance(
|
||||||
border: null,
|
motion: _motion,
|
||||||
// Secondary-label translucency over glass falls below text contrast
|
index: index,
|
||||||
// requirements. The host label role remains readable in both themes.
|
child: FloatingTabButton(
|
||||||
inactiveColor: CupertinoColors.label.resolveFrom(context),
|
key: item.key,
|
||||||
iconSize: FloatingDestinationBar.cupertinoIconSize,
|
cupertino: cupertino,
|
||||||
height: FloatingDestinationBar.cupertinoHeight,
|
motion: _motion,
|
||||||
currentIndex: currentIndex,
|
index: index,
|
||||||
onTap: widget.onTap,
|
count: items.length,
|
||||||
items: [
|
selected: selected,
|
||||||
for (var index = 0; index < items.length; index += 1)
|
size: _size,
|
||||||
BottomNavigationBarItem(
|
iconSize: cupertino
|
||||||
icon: tab(items[index], selected: false, index: index),
|
? FloatingDestinationBar.cupertinoIconSize
|
||||||
activeIcon: tab(items[index], selected: true, index: index),
|
: FloatingDestinationBar.materialIconSize,
|
||||||
),
|
label: item.label,
|
||||||
],
|
icon: selected ? item.selectedIcon ?? item.icon : item.icon,
|
||||||
|
onTap: () => widget.onTap(index),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tab [index]'s icon, animated by the bar: the host swaps a tab's icon
|
|
||||||
/// subtree on selection, so the icon itself holds no animation state.
|
|
||||||
Widget _icon(Widget child, int index) =>
|
|
||||||
FloatingTabEntrance(motion: _motion, index: index, child: child);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The platform-neutral data needed by [FloatingDestinationBar].
|
/// The platform-neutral data needed by [FloatingDestinationBar].
|
||||||
|
|||||||
@@ -0,0 +1,189 @@
|
|||||||
|
import 'dart:ui' show SemanticsRole;
|
||||||
|
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../motion/motion.dart';
|
||||||
|
import 'floating_tab_motion.dart';
|
||||||
|
import 'glass_pill.dart';
|
||||||
|
import 'segmented_bar_motion.dart';
|
||||||
|
|
||||||
|
/// One tab of a floating tab bar: a round [GlassPill] of [size] with the
|
||||||
|
/// tab's icon in the middle.
|
||||||
|
///
|
||||||
|
/// The selected tab fills its circle with the host's selection tint
|
||||||
|
/// (Material `secondaryContainer`, Cupertino active colour at
|
||||||
|
/// [cupertinoTintOpacity]) and draws its icon in the selected colour; the
|
||||||
|
/// tint and colour cross-fade when the selection moves. A press sinks the
|
||||||
|
/// button ([SegmentedPress]), the Material one with its circular ink.
|
||||||
|
///
|
||||||
|
/// It is announced like the host navigation controls' tabs: a tab (and a
|
||||||
|
/// button) named by [label], with its selected state and "tab n of m"
|
||||||
|
/// (in the Material label, or the Cupertino hint). Material shows [label]
|
||||||
|
/// as a tooltip. The icon is painted above the glass, unclipped, so a badge
|
||||||
|
/// on its corner can reach past the circle.
|
||||||
|
class FloatingTabButton extends StatelessWidget {
|
||||||
|
const FloatingTabButton({
|
||||||
|
super.key,
|
||||||
|
required this.cupertino,
|
||||||
|
required this.motion,
|
||||||
|
required this.index,
|
||||||
|
required this.count,
|
||||||
|
required this.selected,
|
||||||
|
required this.size,
|
||||||
|
required this.iconSize,
|
||||||
|
required this.label,
|
||||||
|
required this.icon,
|
||||||
|
required this.onTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool cupertino;
|
||||||
|
final FloatingTabMotion motion;
|
||||||
|
final int index;
|
||||||
|
final int count;
|
||||||
|
final bool selected;
|
||||||
|
final double size;
|
||||||
|
final double iconSize;
|
||||||
|
final String label;
|
||||||
|
|
||||||
|
/// The icon for the current state (the item's selected icon when selected).
|
||||||
|
final Widget icon;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
|
/// The Cupertino selection fill: the active colour at this opacity.
|
||||||
|
static const double cupertinoTintOpacity = 0.18;
|
||||||
|
|
||||||
|
/// The selection fill inside each button (an [Ink] on Material, a
|
||||||
|
/// [DecoratedBox] on Cupertino), for tests.
|
||||||
|
static const Key fillKey = ValueKey('floating-tab-button.fill');
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final colors = _colors(context);
|
||||||
|
final duration = Motion.of(context, Motion.tabSelectDuration);
|
||||||
|
final button = TweenAnimationBuilder<double>(
|
||||||
|
tween: Tween(end: selected ? 1 : 0),
|
||||||
|
duration: duration,
|
||||||
|
curve: Motion.curve,
|
||||||
|
builder: (context, t, _) => _button(context, colors, t),
|
||||||
|
);
|
||||||
|
return MergeSemantics(
|
||||||
|
child: Semantics(
|
||||||
|
role: SemanticsRole.tab,
|
||||||
|
selected: selected,
|
||||||
|
button: true,
|
||||||
|
label: cupertino || kIsWeb ? label : '$label\n${_tabLabel(context)}',
|
||||||
|
hint: cupertino ? _tabLabel(context) : null,
|
||||||
|
// Switching tabs does not unfocus a text field (the composer).
|
||||||
|
child: TextFieldTapRegion(
|
||||||
|
child: cupertino
|
||||||
|
? button
|
||||||
|
: Tooltip(
|
||||||
|
message: label,
|
||||||
|
excludeFromSemantics: true,
|
||||||
|
child: button,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _tabLabel(BuildContext context) => cupertino
|
||||||
|
? CupertinoLocalizations.of(
|
||||||
|
context,
|
||||||
|
).tabSemanticsLabel(tabIndex: index + 1, tabCount: count)
|
||||||
|
: MaterialLocalizations.of(
|
||||||
|
context,
|
||||||
|
).tabLabel(tabIndex: index + 1, tabCount: count);
|
||||||
|
|
||||||
|
({Color tint, Color selectedIcon, Color icon}) _colors(BuildContext context) {
|
||||||
|
if (cupertino) {
|
||||||
|
final active = CupertinoTheme.of(context).primaryColor;
|
||||||
|
return (
|
||||||
|
tint: active.withValues(alpha: cupertinoTintOpacity),
|
||||||
|
selectedIcon: active,
|
||||||
|
// Secondary-label translucency over glass falls below contrast.
|
||||||
|
icon: CupertinoColors.label.resolveFrom(context),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final scheme = Theme.of(context).colorScheme;
|
||||||
|
return (
|
||||||
|
tint: scheme.secondaryContainer,
|
||||||
|
selectedIcon: scheme.onSecondaryContainer,
|
||||||
|
icon: scheme.onSurfaceVariant,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The button at selection progress [t] (0 unselected, 1 selected).
|
||||||
|
Widget _button(
|
||||||
|
BuildContext context,
|
||||||
|
({Color tint, Color selectedIcon, Color icon}) colors,
|
||||||
|
double t,
|
||||||
|
) {
|
||||||
|
final decoration = ShapeDecoration(
|
||||||
|
color: colors.tint.withValues(alpha: colors.tint.a * t),
|
||||||
|
shape: const CircleBorder(),
|
||||||
|
);
|
||||||
|
final Widget fill = cupertino
|
||||||
|
? DecoratedBox(
|
||||||
|
key: fillKey,
|
||||||
|
decoration: decoration,
|
||||||
|
child: MouseRegion(
|
||||||
|
cursor: kIsWeb ? SystemMouseCursors.click : MouseCursor.defer,
|
||||||
|
child: GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: onTap,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// Painted on the glass's Material, under the ink, so the ripple
|
||||||
|
// shows over the selected tint too.
|
||||||
|
: Ink(
|
||||||
|
key: fillKey,
|
||||||
|
decoration: decoration,
|
||||||
|
child: InkResponse(
|
||||||
|
onTap: onTap,
|
||||||
|
customBorder: const CircleBorder(),
|
||||||
|
containedInkWell: true,
|
||||||
|
highlightShape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
Widget glyph = IconTheme.merge(
|
||||||
|
data: IconThemeData(
|
||||||
|
size: iconSize,
|
||||||
|
color: Color.lerp(colors.icon, colors.selectedIcon, t),
|
||||||
|
),
|
||||||
|
child: FloatingTabBounce(motion: motion, index: index, child: icon),
|
||||||
|
);
|
||||||
|
final reveal = GlassReveal.maybeOf(context);
|
||||||
|
if (reveal != null) {
|
||||||
|
// The icon sits above the glass, so it fades with it here.
|
||||||
|
glyph = FadeTransition(
|
||||||
|
opacity: reveal,
|
||||||
|
alwaysIncludeSemantics: true,
|
||||||
|
child: glyph,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return SegmentedPress(
|
||||||
|
cupertino: cupertino,
|
||||||
|
child: SizedBox.square(
|
||||||
|
dimension: size,
|
||||||
|
child: Stack(
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
Positioned.fill(
|
||||||
|
child: GlassPill(
|
||||||
|
cupertino: cupertino,
|
||||||
|
shape: const CircleBorder(),
|
||||||
|
child: fill,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IgnorePointer(child: glyph),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,22 +3,17 @@ import 'dart:math' as math;
|
|||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
import '../motion/motion.dart';
|
import '../motion/motion.dart';
|
||||||
|
import 'glass_pill.dart';
|
||||||
|
|
||||||
/// The animations of one floating tab bar: its tabs popping in, the
|
/// The animations of one floating tab bar: its tab buttons popping in one
|
||||||
/// selection highlight gliding between tabs and the newly selected icon's
|
/// after another, and the newly selected icon's bounce.
|
||||||
/// bounce.
|
|
||||||
///
|
///
|
||||||
/// They live with the bar, not with each tab's icon, because the host
|
/// They live with the bar, not with each button, so a button rebuilt with a
|
||||||
/// navigation controls rebuild a tab's icon subtree whenever it is selected
|
/// new selection (or a new badge) never restarts its entrance: only the bar
|
||||||
/// or deselected: state kept in the icons would restart with every tap.
|
/// decides when its tabs enter.
|
||||||
class FloatingTabMotion {
|
class FloatingTabMotion {
|
||||||
FloatingTabMotion(TickerProvider vsync)
|
FloatingTabMotion(TickerProvider vsync)
|
||||||
: entrance = AnimationController(vsync: vsync),
|
: entrance = AnimationController(vsync: vsync),
|
||||||
slide = AnimationController(
|
|
||||||
vsync: vsync,
|
|
||||||
duration: Motion.tabHighlightDuration,
|
|
||||||
value: 1,
|
|
||||||
),
|
|
||||||
bounce = AnimationController(
|
bounce = AnimationController(
|
||||||
vsync: vsync,
|
vsync: vsync,
|
||||||
duration: Motion.tabBounceDuration,
|
duration: Motion.tabBounceDuration,
|
||||||
@@ -27,17 +22,15 @@ class FloatingTabMotion {
|
|||||||
|
|
||||||
/// Drives every tab's entrance; tab n plays its pop in its own window.
|
/// Drives every tab's entrance; tab n plays its pop in its own window.
|
||||||
final AnimationController entrance;
|
final AnimationController entrance;
|
||||||
final AnimationController slide;
|
|
||||||
final AnimationController bounce;
|
final AnimationController bounce;
|
||||||
|
|
||||||
int _count = 0;
|
int _count = 0;
|
||||||
final List<({Animation<double> pop, Animation<double> opacity})> _entrances =
|
final List<({Animation<double> pop, Animation<double> opacity})> _entrances =
|
||||||
[];
|
[];
|
||||||
double _from = 0;
|
int _selected = 0;
|
||||||
int _to = 0;
|
|
||||||
|
|
||||||
/// Plays the entrance of a bar of [count] tabs, from the start, and places
|
/// Plays the entrance of a bar of [count] tabs, from the start, with
|
||||||
/// the highlight on [selected] without a move.
|
/// [selected] chosen and nothing bouncing.
|
||||||
void enter(
|
void enter(
|
||||||
BuildContext context, {
|
BuildContext context, {
|
||||||
required int count,
|
required int count,
|
||||||
@@ -53,41 +46,25 @@ class FloatingTabMotion {
|
|||||||
entrance.forward(from: 0);
|
entrance.forward(from: 0);
|
||||||
}
|
}
|
||||||
_splitEntrance();
|
_splitEntrance();
|
||||||
_from = selected.toDouble();
|
_selected = selected;
|
||||||
_to = selected;
|
|
||||||
slide.value = 1;
|
|
||||||
bounce.value = 1;
|
bounce.value = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Glides the highlight from where it is now to [selected] and bounces
|
/// Bounces the newly [selected] tab's icon; nothing moves under reduced
|
||||||
/// that tab's icon. Under reduced motion the highlight jumps.
|
/// motion.
|
||||||
void select(BuildContext context, int selected) {
|
void select(BuildContext context, int selected) {
|
||||||
if (selected == _to) return;
|
if (selected == _selected) return;
|
||||||
_from = position;
|
_selected = selected;
|
||||||
_to = selected;
|
if (Motion.of(context, Motion.tabBounceDuration) == Duration.zero) {
|
||||||
if (Motion.of(context, Motion.tabHighlightDuration) == Duration.zero) {
|
|
||||||
slide.value = 1;
|
|
||||||
bounce.value = 1;
|
bounce.value = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
slide.forward(from: 0);
|
|
||||||
bounce.forward(from: 0);
|
bounce.forward(from: 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
double get _travel => Motion.curve.transform(slide.value);
|
|
||||||
|
|
||||||
/// The highlight's position in tab slots: 1.5 is halfway from tab 1 to 2.
|
|
||||||
double get position => _from + (_to - _from) * _travel;
|
|
||||||
|
|
||||||
/// The highlight's width over its height: 1 at rest, at most
|
|
||||||
/// [Motion.tabHighlightStretch] halfway through a move.
|
|
||||||
double get stretch => _from == _to
|
|
||||||
? 1
|
|
||||||
: 1 + (Motion.tabHighlightStretch - 1) * math.sin(math.pi * _travel);
|
|
||||||
|
|
||||||
/// The scale of tab [index]'s icon: only the newly selected one bounces.
|
/// The scale of tab [index]'s icon: only the newly selected one bounces.
|
||||||
double scaleOf(int index) {
|
double scaleOf(int index) {
|
||||||
if (index != _to || bounce.isCompleted) return 1;
|
if (index != _selected || bounce.isCompleted) return 1;
|
||||||
final t = bounce.value;
|
final t = bounce.value;
|
||||||
final rise = t < 0.5 ? t * 2 : (1 - t) * 2;
|
final rise = t < 0.5 ? t * 2 : (1 - t) * 2;
|
||||||
return 1 + (Motion.tabBounceScale - 1) * Curves.easeOut.transform(rise);
|
return 1 + (Motion.tabBounceScale - 1) * Curves.easeOut.transform(rise);
|
||||||
@@ -138,114 +115,66 @@ class FloatingTabMotion {
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
_disposeEntrances();
|
_disposeEntrances();
|
||||||
entrance.dispose();
|
entrance.dispose();
|
||||||
slide.dispose();
|
|
||||||
bounce.dispose();
|
bounce.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tab [index]'s icon (or the highlight behind it) popping in with the bar,
|
/// Tab [index]'s whole button popping in with the bar: it grows from
|
||||||
/// and bouncing when it becomes selected.
|
/// [Motion.tabEntranceScaleBegin] with a gentle overshoot, rising a little,
|
||||||
|
/// while its glass fades in through a [GlassReveal] (so the blur fades with
|
||||||
|
/// the fill instead of snapping on at the end).
|
||||||
class FloatingTabEntrance extends StatelessWidget {
|
class FloatingTabEntrance extends StatelessWidget {
|
||||||
const FloatingTabEntrance({
|
const FloatingTabEntrance({
|
||||||
super.key,
|
super.key,
|
||||||
required this.motion,
|
required this.motion,
|
||||||
required this.index,
|
required this.index,
|
||||||
required this.child,
|
required this.child,
|
||||||
this.bounces = true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final FloatingTabMotion motion;
|
final FloatingTabMotion motion;
|
||||||
final int index;
|
final int index;
|
||||||
final bool bounces;
|
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final entrance = motion.entranceOf(index);
|
final entrance = motion.entranceOf(index);
|
||||||
return FadeTransition(
|
return AnimatedBuilder(
|
||||||
opacity: entrance.opacity,
|
animation: entrance.pop,
|
||||||
// Tabs (and their badge counts) stay announced while they fade in.
|
// The reveal keeps the tab (and its badge count) announced while it
|
||||||
alwaysIncludeSemantics: true,
|
// fades in.
|
||||||
child: AnimatedBuilder(
|
child: GlassReveal(opacity: entrance.opacity, child: child),
|
||||||
animation: Listenable.merge([entrance.pop, motion.bounce]),
|
builder: (context, child) {
|
||||||
child: child,
|
final pop = entrance.pop.value;
|
||||||
builder: (context, child) {
|
final scale =
|
||||||
final pop = entrance.pop.value;
|
Motion.tabEntranceScaleBegin +
|
||||||
final scale =
|
(1 - Motion.tabEntranceScaleBegin) * pop;
|
||||||
Motion.tabEntranceScaleBegin +
|
return Transform.translate(
|
||||||
(1 - Motion.tabEntranceScaleBegin) * pop;
|
offset: Offset(0, (1 - pop) * Motion.tabEntranceSlideDistance),
|
||||||
return Transform.translate(
|
child: Transform.scale(scale: scale, child: child),
|
||||||
offset: Offset(0, (1 - pop) * Motion.tabEntranceSlideDistance),
|
);
|
||||||
child: Transform.scale(
|
},
|
||||||
scale: scale * (bounces ? motion.scaleOf(index) : 1),
|
|
||||||
child: child,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The one selection highlight of a bar, behind its icons: a circle of
|
/// Tab [index]'s icon, bouncing briefly when it becomes selected.
|
||||||
/// [size] centred on the selected tab, gliding (and stretching along the way)
|
class FloatingTabBounce extends StatelessWidget {
|
||||||
/// to a newly selected one. It takes no taps and says nothing; the host's
|
const FloatingTabBounce({
|
||||||
/// tabs carry the selected state.
|
|
||||||
///
|
|
||||||
/// It is laid out over tab 0 (its slot, or its icon) and paints itself
|
|
||||||
/// [slot] widths along the reading direction per tab, unclipped.
|
|
||||||
class FloatingTabHighlight extends StatelessWidget {
|
|
||||||
const FloatingTabHighlight({
|
|
||||||
super.key,
|
super.key,
|
||||||
required this.motion,
|
required this.motion,
|
||||||
required this.slot,
|
required this.index,
|
||||||
required this.size,
|
required this.child,
|
||||||
required this.color,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final FloatingTabMotion motion;
|
final FloatingTabMotion motion;
|
||||||
|
final int index;
|
||||||
/// The distance between neighbouring tabs' centres.
|
final Widget child;
|
||||||
final double slot;
|
|
||||||
final double size;
|
|
||||||
final Color color;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => AnimatedBuilder(
|
||||||
final direction = Directionality.of(context) == TextDirection.rtl ? -1 : 1;
|
animation: motion.bounce,
|
||||||
return IgnorePointer(
|
child: child,
|
||||||
child: ExcludeSemantics(
|
builder: (context, child) =>
|
||||||
child: AnimatedBuilder(
|
Transform.scale(scale: motion.scaleOf(index), child: child),
|
||||||
animation: motion.slide,
|
);
|
||||||
builder: (context, _) {
|
|
||||||
final width = size * motion.stretch;
|
|
||||||
return OverflowBox(
|
|
||||||
minWidth: 0,
|
|
||||||
minHeight: 0,
|
|
||||||
maxWidth: double.infinity,
|
|
||||||
maxHeight: double.infinity,
|
|
||||||
child: Transform.translate(
|
|
||||||
offset: Offset(direction * slot * motion.position, 0),
|
|
||||||
child: FloatingTabEntrance(
|
|
||||||
motion: motion,
|
|
||||||
index: motion.position.round(),
|
|
||||||
bounces: false,
|
|
||||||
child: SizedBox(
|
|
||||||
width: width,
|
|
||||||
height: size,
|
|
||||||
child: DecoratedBox(
|
|
||||||
decoration: ShapeDecoration(
|
|
||||||
color: color,
|
|
||||||
shape: const StadiumBorder(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,12 +34,8 @@ abstract final class Motion {
|
|||||||
/// The fraction of a tab's entrance spent fading in.
|
/// The fraction of a tab's entrance spent fading in.
|
||||||
static const double tabEntranceOpacityPortion = 0.6;
|
static const double tabEntranceOpacityPortion = 0.6;
|
||||||
|
|
||||||
/// How long a tab bar's selection highlight takes to glide to a new tab.
|
/// How long a tab button's selection tint takes to cross-fade.
|
||||||
static const Duration tabHighlightDuration = Duration(milliseconds: 250);
|
static const Duration tabSelectDuration = Duration(milliseconds: 220);
|
||||||
|
|
||||||
/// The highlight's width, relative to its height, halfway through a move;
|
|
||||||
/// it is a circle again at rest.
|
|
||||||
static const double tabHighlightStretch = 1.25;
|
|
||||||
|
|
||||||
/// The newly selected tab icon's brief bounce.
|
/// The newly selected tab icon's brief bounce.
|
||||||
static const Duration tabBounceDuration = Duration(milliseconds: 180);
|
static const Duration tabBounceDuration = Duration(milliseconds: 180);
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
# Floating tab bars: one round glass button per tab
|
||||||
|
|
||||||
|
`FloatingDestinationBar` (the shell's destinations and every page's tabs) was
|
||||||
|
one glass pill holding the host `NavigationBar` / `CupertinoTabBar`, with a
|
||||||
|
single highlight circle gliding between tabs. Each tab is now its own round
|
||||||
|
`GlassPill` button (`FloatingTabButton`), in a row at the same place
|
||||||
|
(bottom right, `kFloatingBarMargin`, safe area; page tabs `kStackedBarGap`
|
||||||
|
above the shell row).
|
||||||
|
|
||||||
|
- Size: 52 px Material, 50 px Cupertino (the old circle was 44/42); icons
|
||||||
|
28/30 as before; gaps 12/10. The bar's height is the button size.
|
||||||
|
`FloatingDestinationBar.rowWidth`, `buttonSize`, `buttonGap` and `rowKey`
|
||||||
|
replace `pillWidth`, the highlight/edge-gap constants and `highlightKey`.
|
||||||
|
A row narrower than its natural width shrinks its gaps, then scales down.
|
||||||
|
- Selection: the selected button fills with `secondaryContainer` (Material) or
|
||||||
|
the active colour at 18% (Cupertino) and draws its icon in
|
||||||
|
`onSecondaryContainer` / the active colour; the fill and icon colour
|
||||||
|
cross-fade (`Motion.tabSelectDuration`), and the new icon bounces as before.
|
||||||
|
The gliding highlight was dropped: between separate buttons it would cross
|
||||||
|
the gaps over the content.
|
||||||
|
- Entrance: each whole button pops in (0.6 -> 1, ease-out-back, 70 ms
|
||||||
|
stagger), its glass fading through `GlassReveal`; only when the bar first
|
||||||
|
builds or its tab set changes.
|
||||||
|
- Press: `SegmentedPress`, as in the top bar; Material keeps its circular ink.
|
||||||
|
- Semantics: the row is a `SemanticsRole.tabBar`; each button a merged
|
||||||
|
`SemanticsRole.tab` button with its selected state, named by its label, and
|
||||||
|
"Tab n of m" in the label (Material, off the web, as `NavigationBar`) or the
|
||||||
|
hint (Cupertino, as `CupertinoTabBar`). Material shows the label as a
|
||||||
|
tooltip. `item.key` is on each button.
|
||||||
|
- Badges: the icon is painted above the glass, outside its circular clip, so
|
||||||
|
a badge on the icon's corner is not cut off.
|
||||||
|
- Blur: the buttons of a bar share one `BackdropGroup`, so on Impeller they
|
||||||
|
read the content behind them once (see `perf-glass-chrome.md`; CanvasKit
|
||||||
|
ignores backdrop keys and blurs each button).
|
||||||
|
|
||||||
|
Evidence: `/tmp/tab-buttons/` (start-*, flow-* at 560x900 and 880x1000,
|
||||||
|
Material and Cupertino; light-* shots). The kit's `film` step after `open`
|
||||||
|
recorded a cropped frame (560x347, 756x469); re-applying the viewport size
|
||||||
|
before filming (as the films here did) gives full-size frames.
|
||||||
@@ -127,7 +127,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
expect(navigator.canPop(), isTrue);
|
expect(navigator.canPop(), isTrue);
|
||||||
expect(findNativeBack(), findsOneWidget);
|
expect(findNativeBack(), findsOneWidget);
|
||||||
expect(find.byType(NavigationBar), findsNothing);
|
expect(find.byType(FloatingDestinationBar), findsNothing);
|
||||||
|
|
||||||
await tester.pageBack();
|
await tester.pageBack();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ 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/floating_destination_bar.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('code-like values still use native host typography', (
|
testWidgets('code-like values still use native host typography', (
|
||||||
@@ -61,17 +60,14 @@ void main() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
// The host's own tab bar inside the shared glass pill.
|
// One floating bar of separate round tab buttons.
|
||||||
expect(
|
expect(find.byType(FloatingDestinationBar), findsOneWidget);
|
||||||
find.byType(cupertino ? CupertinoTabBar : NavigationBar),
|
final pill = tester.getRect(find.byKey(FloatingDestinationBar.rowKey));
|
||||||
findsOneWidget,
|
|
||||||
);
|
|
||||||
final pill = tester.getRect(find.byType(GlassPill));
|
|
||||||
// Sized to its three tabs at the right edge, on a phone as when wide.
|
// Sized to its three tabs at the right edge, on a phone as when wide.
|
||||||
expect(pill.right, width - 16);
|
expect(pill.right, width - 16);
|
||||||
expect(
|
expect(
|
||||||
pill.width,
|
pill.width,
|
||||||
FloatingDestinationBar.pillWidth(
|
FloatingDestinationBar.rowWidth(
|
||||||
cupertino: cupertino,
|
cupertino: cupertino,
|
||||||
tabs: PipelineDetailTab.values.length,
|
tabs: PipelineDetailTab.values.length,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import 'package:pipelines_app/features/pipelines/pipeline_repository.dart';
|
|||||||
import 'package:pipelines_app/features/pipelines/pipelines_controller.dart';
|
import 'package:pipelines_app/features/pipelines/pipelines_controller.dart';
|
||||||
import 'package:pipelines_app/features/pipelines/screen.dart';
|
import 'package:pipelines_app/features/pipelines/screen.dart';
|
||||||
import 'package:pipelines_app/features/pipelines/widgets/pipeline_detail_panel.dart';
|
import 'package:pipelines_app/features/pipelines/widgets/pipeline_detail_panel.dart';
|
||||||
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||||
|
|
||||||
import 'fixtures.dart';
|
import 'fixtures.dart';
|
||||||
import 'test_helpers.dart';
|
import 'test_helpers.dart';
|
||||||
@@ -139,7 +140,7 @@ void main() {
|
|||||||
expect(
|
expect(
|
||||||
find.descendant(
|
find.descendant(
|
||||||
of: find.byKey(const Key('pipeline-detail-tabs')),
|
of: find.byKey(const Key('pipeline-detail-tabs')),
|
||||||
matching: find.byType(CupertinoTabBar),
|
matching: find.byType(FloatingDestinationBar),
|
||||||
),
|
),
|
||||||
findsOneWidget,
|
findsOneWidget,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ 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/floating_destination_bar.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
|
||||||
|
|
||||||
import 'run_detail_graph_support.dart';
|
import 'run_detail_graph_support.dart';
|
||||||
|
|
||||||
@@ -63,7 +62,10 @@ void main() {
|
|||||||
// The tabs are the floating glass bar: on this 900px detail it is sized
|
// The tabs are the floating glass bar: on this 900px detail it is sized
|
||||||
// to its tabs at the right edge, above the bottom.
|
// to its tabs at the right edge, above the bottom.
|
||||||
final pill = tester.getRect(
|
final pill = tester.getRect(
|
||||||
find.descendant(of: strip, matching: find.byType(GlassPill)),
|
find.descendant(
|
||||||
|
of: strip,
|
||||||
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(pill.right, 900 - 16);
|
expect(pill.right, 900 - 16);
|
||||||
expect(pill.bottom, 1000 - 16);
|
expect(pill.bottom, 1000 - 16);
|
||||||
@@ -89,13 +91,16 @@ void main() {
|
|||||||
await pumpRunDetail(tester, platform, size: const Size(390, 844));
|
await pumpRunDetail(tester, platform, size: const Size(390, 844));
|
||||||
final strip = find.byKey(const Key('run-detail-tabs'));
|
final strip = find.byKey(const Key('run-detail-tabs'));
|
||||||
final pill = tester.getRect(
|
final pill = tester.getRect(
|
||||||
find.descendant(of: strip, matching: find.byType(GlassPill)),
|
find.descendant(
|
||||||
|
of: strip,
|
||||||
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
final body = find.byKey(const Key('run-detail-tab-body-summary'));
|
final body = find.byKey(const Key('run-detail-tab-body-summary'));
|
||||||
// Sized to its tabs at the right, floating above the bottom.
|
// Sized to its tabs at the right, floating above the bottom.
|
||||||
expect(
|
expect(
|
||||||
pill.width,
|
pill.width,
|
||||||
FloatingDestinationBar.pillWidth(
|
FloatingDestinationBar.rowWidth(
|
||||||
cupertino: platform != RunDetailTestPlatform.material,
|
cupertino: platform != RunDetailTestPlatform.material,
|
||||||
tabs: renderedRunDetailTabs.length,
|
tabs: renderedRunDetailTabs.length,
|
||||||
),
|
),
|
||||||
@@ -125,7 +130,10 @@ void main() {
|
|||||||
|
|
||||||
await pumpRunDetail(tester, platform, size: const Size(1000, 844));
|
await pumpRunDetail(tester, platform, size: const Size(1000, 844));
|
||||||
final widePill = tester.getRect(
|
final widePill = tester.getRect(
|
||||||
find.descendant(of: strip, matching: find.byType(GlassPill)),
|
find.descendant(
|
||||||
|
of: strip,
|
||||||
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(widePill.right, 1000 - 16);
|
expect(widePill.right, 1000 - 16);
|
||||||
expect(widePill.bottom, 844 - 16);
|
expect(widePill.bottom, 844 - 16);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import 'package:pipelines_app/features/graph/widgets/stage_definition_view.dart'
|
|||||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_facts.dart';
|
import 'package:pipelines_app/features/runs/ui/run_detail_visit_facts.dart';
|
||||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_sections.dart';
|
import 'package:pipelines_app/features/runs/ui/run_detail_visit_sections.dart';
|
||||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session_state.dart';
|
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session_state.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||||
|
|
||||||
import 'run_detail_graph_support.dart';
|
import 'run_detail_graph_support.dart';
|
||||||
import 'run_detail_visit_support.dart';
|
import 'run_detail_visit_support.dart';
|
||||||
@@ -241,7 +241,7 @@ void main() {
|
|||||||
final pill = tester.getRect(
|
final pill = tester.getRect(
|
||||||
find.descendant(
|
find.descendant(
|
||||||
of: find.byType(RunVisitSectionStrip),
|
of: find.byType(RunVisitSectionStrip),
|
||||||
matching: find.byType(GlassPill),
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(pill.right, size.width - 16);
|
expect(pill.right, size.width - 16);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||||
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||||
|
|
||||||
/// The Runs tab mirrors the attention count in every mount of both hosts:
|
/// The Runs tab mirrors the attention count in every mount of both hosts:
|
||||||
/// the floating tab bar at full width on a phone and right-aligned on a wide
|
/// the floating tab bar at full width on a phone and right-aligned on a wide
|
||||||
@@ -35,7 +36,7 @@ void main() {
|
|||||||
) async {
|
) async {
|
||||||
final semantics = tester.ensureSemantics();
|
final semantics = tester.ensureSemantics();
|
||||||
await pumpShell(tester, width: width, cupertino: false, count: 3);
|
await pumpShell(tester, width: width, cupertino: false, count: 3);
|
||||||
expect(find.byType(NavigationBar), findsOneWidget);
|
expect(find.byType(FloatingDestinationBar), findsOneWidget);
|
||||||
expect(find.byType(NavigationRail), findsNothing);
|
expect(find.byType(NavigationRail), findsNothing);
|
||||||
final badge = find.byType(Badge);
|
final badge = find.byType(Badge);
|
||||||
expect(badge, findsOneWidget);
|
expect(badge, findsOneWidget);
|
||||||
@@ -74,7 +75,7 @@ void main() {
|
|||||||
) async {
|
) async {
|
||||||
final semantics = tester.ensureSemantics();
|
final semantics = tester.ensureSemantics();
|
||||||
await pumpShell(tester, width: width, cupertino: true, count: 3);
|
await pumpShell(tester, width: width, cupertino: true, count: 3);
|
||||||
expect(find.byType(CupertinoTabBar), findsOneWidget);
|
expect(find.byType(FloatingDestinationBar), findsOneWidget);
|
||||||
expect(find.byType(Badge), findsNothing, reason: 'no Material badge');
|
expect(find.byType(Badge), findsNothing, reason: 'no Material badge');
|
||||||
expect(find.text('3'), findsOneWidget);
|
expect(find.text('3'), findsOneWidget);
|
||||||
expect(find.bySemanticsLabel(needingAttention), findsOneWidget);
|
expect(find.bySemanticsLabel(needingAttention), findsOneWidget);
|
||||||
|
|||||||
@@ -4,14 +4,13 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||||
import 'package:pipelines_app/shell/destination.dart';
|
import 'package:pipelines_app/shell/destination.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
|
||||||
|
|
||||||
/// The shell's one floating glass tab bar: full width on a phone, sized to its
|
/// The shell's one floating glass tab bar: full width on a phone, sized to its
|
||||||
/// tabs at the right edge on a wide window, with content behind it.
|
/// tabs at the right edge on a wide window, with content behind it.
|
||||||
void main() {
|
void main() {
|
||||||
Finder pill() => find.descendant(
|
Finder pill() => find.descendant(
|
||||||
of: find.byType(FloatingDestinationBar),
|
of: find.byType(FloatingDestinationBar),
|
||||||
matching: find.byType(GlassPill),
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<void> setSize(WidgetTester tester, Size size) async {
|
Future<void> setSize(WidgetTester tester, Size size) async {
|
||||||
@@ -56,7 +55,7 @@ void main() {
|
|||||||
final rect = tester.getRect(pill());
|
final rect = tester.getRect(pill());
|
||||||
expect(
|
expect(
|
||||||
rect.width,
|
rect.width,
|
||||||
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
|
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
||||||
);
|
);
|
||||||
expect(rect.right, 390 - 16);
|
expect(rect.right, 390 - 16);
|
||||||
expect(rect.bottom, 844 - 16);
|
expect(rect.bottom, 844 - 16);
|
||||||
@@ -81,7 +80,7 @@ void main() {
|
|||||||
// Four icon-only tabs, with the wider neighbour gaps derived by the bar.
|
// Four icon-only tabs, with the wider neighbour gaps derived by the bar.
|
||||||
expect(
|
expect(
|
||||||
rect.width,
|
rect.width,
|
||||||
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
|
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
||||||
);
|
);
|
||||||
// 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);
|
||||||
@@ -135,7 +134,7 @@ void main() {
|
|||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(
|
expect(
|
||||||
tester.getRect(pill()).width,
|
tester.getRect(pill()).width,
|
||||||
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
|
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
||||||
);
|
);
|
||||||
expect(tester.getRect(pill()).right, 390 - 16);
|
expect(tester.getRect(pill()).right, 390 - 16);
|
||||||
expect(tester.state(find.byType(StatefulBuilder)), same(state));
|
expect(tester.state(find.byType(StatefulBuilder)), same(state));
|
||||||
@@ -199,7 +198,7 @@ void main() {
|
|||||||
// Sized to its four tabs at the right, as on any width.
|
// Sized to its four tabs at the right, as on any width.
|
||||||
expect(
|
expect(
|
||||||
tester.getRect(pill()).width,
|
tester.getRect(pill()).width,
|
||||||
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
|
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
||||||
);
|
);
|
||||||
expect(tester.getRect(pill()).right, 320 - 16);
|
expect(tester.getRect(pill()).right, 320 - 16);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,14 +161,14 @@ void main() {
|
|||||||
find
|
find
|
||||||
.ancestor(
|
.ancestor(
|
||||||
of: find.byKey(const ValueKey('shell.destination.runs')).first,
|
of: find.byKey(const ValueKey('shell.destination.runs')).first,
|
||||||
matching: find.byType(GlassPill),
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
)
|
)
|
||||||
.first,
|
.first,
|
||||||
);
|
);
|
||||||
final itemTabs = tester.getRect(
|
final itemTabs = tester.getRect(
|
||||||
find.descendant(
|
find.descendant(
|
||||||
of: find.byKey(const Key('item-tabs')),
|
of: find.byKey(const Key('item-tabs')),
|
||||||
matching: find.byType(GlassPill),
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final body = tester.getRect(
|
final body = tester.getRect(
|
||||||
@@ -214,7 +214,7 @@ void main() {
|
|||||||
final tabs = tester.getRect(
|
final tabs = tester.getRect(
|
||||||
find.descendant(
|
find.descendant(
|
||||||
of: find.byKey(const Key('item-tabs')),
|
of: find.byKey(const Key('item-tabs')),
|
||||||
matching: find.byType(GlassPill),
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(tabs.bottom, greaterThan(844 - 40));
|
expect(tabs.bottom, greaterThan(844 - 40));
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import 'package:pipelines_app/shell/adaptive_shell.dart';
|
|||||||
import 'package:pipelines_app/shell/destination.dart';
|
import 'package:pipelines_app/shell/destination.dart';
|
||||||
import 'package:pipelines_app/shell/shell_bar.dart';
|
import 'package:pipelines_app/shell/shell_bar.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
|
||||||
|
|
||||||
Widget _app({required bool cupertino, required bool open, VoidCallback? back}) {
|
Widget _app({required bool cupertino, required bool open, VoidCallback? back}) {
|
||||||
final shell = AdaptiveShell(
|
final shell = AdaptiveShell(
|
||||||
@@ -88,12 +87,12 @@ void main() {
|
|||||||
|
|
||||||
final destinationPill = find.descendant(
|
final destinationPill = find.descendant(
|
||||||
of: find.byType(FloatingDestinationBar),
|
of: find.byType(FloatingDestinationBar),
|
||||||
matching: find.byType(GlassPill),
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
);
|
);
|
||||||
// Sized to its four tabs at the bottom right.
|
// Sized to its four tabs at the bottom right.
|
||||||
expect(
|
expect(
|
||||||
tester.getSize(destinationPill).width,
|
tester.getSize(destinationPill).width,
|
||||||
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
|
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
||||||
);
|
);
|
||||||
expect(tester.getRect(destinationPill).right, 390 - 16);
|
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')));
|
||||||
@@ -154,7 +153,7 @@ void main() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
await tester.pumpWidget(shell());
|
await tester.pumpWidget(shell());
|
||||||
expect(find.byType(NavigationBar), findsOneWidget);
|
expect(find.byType(FloatingDestinationBar), findsOneWidget);
|
||||||
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
|
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
|
||||||
navigator.push(
|
navigator.push(
|
||||||
MaterialPageRoute<void>(
|
MaterialPageRoute<void>(
|
||||||
@@ -162,13 +161,16 @@ void main() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.byType(NavigationBar), findsNothing);
|
expect(find.byType(FloatingDestinationBar), findsNothing);
|
||||||
expect(find.byType(NavigationBar, skipOffstage: false), findsOneWidget);
|
expect(
|
||||||
|
find.byType(FloatingDestinationBar, skipOffstage: false),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
await navigator.maybePop();
|
await navigator.maybePop();
|
||||||
await tester.pump(const Duration(milliseconds: 16));
|
await tester.pump(const Duration(milliseconds: 16));
|
||||||
expect(find.byType(NavigationBar), findsOneWidget);
|
expect(find.byType(FloatingDestinationBar), findsOneWidget);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.byType(NavigationBar), findsOneWidget);
|
expect(find.byType(FloatingDestinationBar), findsOneWidget);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import 'package:pipelines_app/shell/destination.dart';
|
|||||||
import 'package:pipelines_app/shell/list_detail.dart';
|
import 'package:pipelines_app/shell/list_detail.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart';
|
import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
|
||||||
|
|
||||||
/// While a tab shows its list beside an open item, the shell's destination
|
/// While a tab shows its list beside an open item, the shell's destination
|
||||||
/// bar keeps its place at the bottom right (near the thumb). The item's own
|
/// bar keeps its place at the bottom right (near the thumb). The item's own
|
||||||
@@ -101,7 +100,7 @@ void main() {
|
|||||||
find
|
find
|
||||||
.ancestor(
|
.ancestor(
|
||||||
of: find.byKey(const ValueKey('shell.destination.chat')).first,
|
of: find.byKey(const ValueKey('shell.destination.chat')).first,
|
||||||
matching: find.byType(GlassPill),
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
)
|
)
|
||||||
.first,
|
.first,
|
||||||
);
|
);
|
||||||
@@ -160,7 +159,7 @@ void main() {
|
|||||||
find
|
find
|
||||||
.descendant(
|
.descendant(
|
||||||
of: find.byKey(const Key('detail-tabs')),
|
of: find.byKey(const Key('detail-tabs')),
|
||||||
matching: find.byType(GlassPill),
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
)
|
)
|
||||||
.first,
|
.first,
|
||||||
);
|
);
|
||||||
@@ -200,7 +199,7 @@ void main() {
|
|||||||
final pill = destinationPill(tester);
|
final pill = destinationPill(tester);
|
||||||
expect(
|
expect(
|
||||||
pill.width,
|
pill.width,
|
||||||
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
|
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
||||||
);
|
);
|
||||||
expect(pill.right, closeTo(390 - kFloatingBarMargin, 0.5));
|
expect(pill.right, closeTo(390 - kFloatingBarMargin, 0.5));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import 'package:pipelines_app/shell/destination.dart';
|
|||||||
import 'package:pipelines_app/shell/detail_page.dart';
|
import 'package:pipelines_app/shell/detail_page.dart';
|
||||||
import 'package:pipelines_app/shell/list_detail.dart';
|
import 'package:pipelines_app/shell/list_detail.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart';
|
import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||||
|
|
||||||
import '../features/runs/ui/run_detail_graph_support.dart';
|
import '../features/runs/ui/run_detail_graph_support.dart';
|
||||||
import '../features/runs/ui/run_detail_visit_support.dart';
|
import '../features/runs/ui/run_detail_visit_support.dart';
|
||||||
@@ -21,14 +21,17 @@ import '../features/runs/ui/run_detail_visit_support.dart';
|
|||||||
/// the detail pane instead of covering the shell.
|
/// the detail pane instead of covering the shell.
|
||||||
void main() {
|
void main() {
|
||||||
Rect pillOf(WidgetTester tester, Finder owner) => tester.getRect(
|
Rect pillOf(WidgetTester tester, Finder owner) => tester.getRect(
|
||||||
find.descendant(of: owner, matching: find.byType(GlassPill)).first,
|
find.descendant(
|
||||||
|
of: owner,
|
||||||
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Rect shellPill(WidgetTester tester) => tester.getRect(
|
Rect shellPill(WidgetTester tester) => tester.getRect(
|
||||||
find
|
find
|
||||||
.ancestor(
|
.ancestor(
|
||||||
of: find.byKey(const ValueKey('shell.destination.runs')).first,
|
of: find.byKey(const ValueKey('shell.destination.runs')).first,
|
||||||
matching: find.byType(GlassPill),
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
)
|
)
|
||||||
.first,
|
.first,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -171,14 +171,19 @@ void main() {
|
|||||||
final body = tester.getRect(
|
final body = tester.getRect(
|
||||||
find.byKey(const ValueKey('list-detail-body')),
|
find.byKey(const ValueKey('list-detail-body')),
|
||||||
);
|
);
|
||||||
final tabs = pillsOf(tester, find.byKey(const Key('item-tabs'))).single;
|
final tabs = tester.getRect(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byKey(const Key('item-tabs')),
|
||||||
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
|
),
|
||||||
|
);
|
||||||
expect(tabs.left, greaterThanOrEqualTo(body.left));
|
expect(tabs.left, greaterThanOrEqualTo(body.left));
|
||||||
expect(tabs.right, lessThanOrEqualTo(body.right));
|
expect(tabs.right, lessThanOrEqualTo(body.right));
|
||||||
final shellTabs = tester.getRect(
|
final shellTabs = tester.getRect(
|
||||||
find
|
find
|
||||||
.ancestor(
|
.ancestor(
|
||||||
of: find.byKey(const ValueKey('shell.destination.runs')).first,
|
of: find.byKey(const ValueKey('shell.destination.runs')).first,
|
||||||
matching: find.byType(GlassPill),
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||||
)
|
)
|
||||||
.first,
|
.first,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,368 +0,0 @@
|
|||||||
import 'dart:math' as math;
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The bar's one selection highlight, at rest on tab [index].
|
|
||||||
Rect circle(WidgetTester tester, int index) {
|
|
||||||
final rect = tester.getRect(
|
|
||||||
find.descendant(
|
|
||||||
of: find.byKey(FloatingDestinationBar.highlightKey),
|
|
||||||
matching: find.byType(DecoratedBox),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
final icon = tester.getCenter(
|
|
||||||
find.descendant(
|
|
||||||
of: find.byKey(tabKey(index)),
|
|
||||||
matching: find.byIcon(icons[index]),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(rect.center.dx, moreOrLessEquals(icon.dx, epsilon: 0.5));
|
|
||||||
expect(rect.center.dy, moreOrLessEquals(icon.dy, epsilon: 0.5));
|
|
||||||
return rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
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';
|
|
||||||
|
|
||||||
testWidgets('$host: icon and selection circle sizes grow together', (
|
|
||||||
tester,
|
|
||||||
) async {
|
|
||||||
await pump(
|
|
||||||
tester,
|
|
||||||
cupertino: cupertino,
|
|
||||||
size: const Size(390, 844),
|
|
||||||
child: Align(
|
|
||||||
alignment: Alignment.bottomCenter,
|
|
||||||
child: bar(cupertino: cupertino, count: 2, selected: 0),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
final icon = tester.getRect(find.byIcon(icons.first));
|
|
||||||
final mark = circle(tester, 0);
|
|
||||||
final iconSize = cupertino
|
|
||||||
? FloatingDestinationBar.cupertinoIconSize
|
|
||||||
: FloatingDestinationBar.materialIconSize;
|
|
||||||
final highlightSize = cupertino
|
|
||||||
? FloatingDestinationBar.cupertinoHighlightSize
|
|
||||||
: FloatingDestinationBar.materialHighlightSize;
|
|
||||||
expect(icon.width, iconSize);
|
|
||||||
expect(icon.height, iconSize);
|
|
||||||
expect(mark.width, highlightSize);
|
|
||||||
expect(mark.height, highlightSize);
|
|
||||||
});
|
|
||||||
|
|
||||||
testWidgets(
|
|
||||||
'$host: tab entrance animates once and respects reduced motion',
|
|
||||||
(tester) async {
|
|
||||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
|
||||||
const FakeAccessibilityFeatures(disableAnimations: false);
|
|
||||||
addTearDown(() {
|
|
||||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
|
||||||
const FakeAccessibilityFeatures(disableAnimations: true);
|
|
||||||
});
|
|
||||||
tester.view.physicalSize = const Size(390, 844);
|
|
||||||
tester.view.devicePixelRatio = 1;
|
|
||||||
addTearDown(tester.view.reset);
|
|
||||||
var selected = 0;
|
|
||||||
await tester.pumpWidget(
|
|
||||||
cupertino
|
|
||||||
? CupertinoApp(
|
|
||||||
home: CupertinoPageScaffold(
|
|
||||||
child: MediaQuery(
|
|
||||||
data: const MediaQueryData(disableAnimations: false),
|
|
||||||
child: StatefulBuilder(
|
|
||||||
builder: (context, setState) => bar(
|
|
||||||
cupertino: cupertino,
|
|
||||||
count: 3,
|
|
||||||
selected: selected,
|
|
||||||
onTap: (index) => setState(() => selected = index),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: MaterialApp(
|
|
||||||
home: Scaffold(
|
|
||||||
body: MediaQuery(
|
|
||||||
data: const MediaQueryData(disableAnimations: false),
|
|
||||||
child: StatefulBuilder(
|
|
||||||
builder: (context, setState) => bar(
|
|
||||||
cupertino: cupertino,
|
|
||||||
count: 3,
|
|
||||||
selected: selected,
|
|
||||||
onTap: (index) => setState(() => selected = index),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
Finder entranceOf(int index) => find
|
|
||||||
.descendant(
|
|
||||||
of: find.byKey(tabKey(index)),
|
|
||||||
matching: find.byWidgetPredicate(
|
|
||||||
(widget) =>
|
|
||||||
widget is FadeTransition && widget.child is AnimatedBuilder,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.last;
|
|
||||||
final entrance = entranceOf(0);
|
|
||||||
double firstOpacity() =>
|
|
||||||
tester.widget<FadeTransition>(entranceOf(0)).opacity.value;
|
|
||||||
double lastOpacity() =>
|
|
||||||
tester.widget<FadeTransition>(entranceOf(2)).opacity.value;
|
|
||||||
expect(firstOpacity(), 0);
|
|
||||||
expect(lastOpacity(), 0);
|
|
||||||
await tester.pump(const Duration(milliseconds: 130));
|
|
||||||
expect(firstOpacity(), greaterThan(0.9));
|
|
||||||
expect(lastOpacity(), lessThan(0.2));
|
|
||||||
await tester.pump(const Duration(milliseconds: 270));
|
|
||||||
expect(firstOpacity(), 1);
|
|
||||||
expect(lastOpacity(), 1);
|
|
||||||
await tester.tap(find.byKey(tabKey(1)));
|
|
||||||
await tester.pump();
|
|
||||||
|
|
||||||
await tester.pumpWidget(
|
|
||||||
MediaQuery(
|
|
||||||
data: const MediaQueryData(disableAnimations: true),
|
|
||||||
child: cupertino
|
|
||||||
? CupertinoApp(
|
|
||||||
home: CupertinoPageScaffold(
|
|
||||||
child: bar(cupertino: cupertino, count: 3, selected: 0),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: MaterialApp(
|
|
||||||
home: Scaffold(
|
|
||||||
body: bar(cupertino: cupertino, count: 3, selected: 0),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(tester.widget<FadeTransition>(entrance.first).opacity.value, 1);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
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, with the larger named neighbour gap.
|
|
||||||
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 box = pill(tester);
|
|
||||||
final edgeGap = last.top - box.top;
|
|
||||||
final requestedNeighbourGap = cupertino
|
|
||||||
? FloatingDestinationBar.cupertinoNeighbourGap
|
|
||||||
: FloatingDestinationBar.materialNeighbourGap;
|
|
||||||
final neighbourGap = math.min(
|
|
||||||
requestedNeighbourGap,
|
|
||||||
(box.width -
|
|
||||||
2 *
|
|
||||||
(cupertino
|
|
||||||
? FloatingDestinationBar.cupertinoEdgeGap
|
|
||||||
: FloatingDestinationBar.materialEdgeGap) -
|
|
||||||
count * last.width) /
|
|
||||||
(count - 1),
|
|
||||||
);
|
|
||||||
for (var index = 1; index < count; index += 1) {
|
|
||||||
expect(
|
|
||||||
centres[index] - centres[index - 1] - last.width,
|
|
||||||
moreOrLessEquals(neighbourGap, epsilon: 1),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect(
|
|
||||||
neighbourGap - edgeGap,
|
|
||||||
moreOrLessEquals(
|
|
||||||
neighbourGap -
|
|
||||||
(cupertino
|
|
||||||
? FloatingDestinationBar.cupertinoEdgeGap
|
|
||||||
: FloatingDestinationBar.materialEdgeGap),
|
|
||||||
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));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,254 @@
|
|||||||
|
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 a row of separate round glass buttons at the
|
||||||
|
/// bottom right on every width: each tab its own circle of the named size,
|
||||||
|
/// evenly spaced, the row keeping the margins from the edges, 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Tab [index]'s glass circle.
|
||||||
|
Rect button(WidgetTester tester, int index) => tester.getRect(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byKey(tabKey(index)),
|
||||||
|
matching: find.byType(GlassPill),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Rect row(WidgetTester tester) =>
|
||||||
|
tester.getRect(find.byKey(FloatingDestinationBar.rowKey));
|
||||||
|
|
||||||
|
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),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (final cupertino in [false, true]) {
|
||||||
|
final host = cupertino ? 'Cupertino' : 'Material';
|
||||||
|
final diameter = FloatingDestinationBar.buttonSize(cupertino: cupertino);
|
||||||
|
final gap = FloatingDestinationBar.buttonGap(cupertino: cupertino);
|
||||||
|
final iconSize = cupertino
|
||||||
|
? FloatingDestinationBar.cupertinoIconSize
|
||||||
|
: FloatingDestinationBar.materialIconSize;
|
||||||
|
|
||||||
|
test('$host: buttons are larger than the old 44/42 circle, hit targets '
|
||||||
|
'meet the platform minimum', () {
|
||||||
|
expect(diameter, cupertino ? 50 : 52);
|
||||||
|
expect(diameter, greaterThanOrEqualTo(cupertino ? 44 : 48));
|
||||||
|
expect(gap, inInclusiveRange(10, 12));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('$host: each tab is its own glass circle with the icon '
|
||||||
|
'centred in it', (tester) async {
|
||||||
|
await pump(
|
||||||
|
tester,
|
||||||
|
cupertino: cupertino,
|
||||||
|
size: const Size(390, 844),
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.bottomCenter,
|
||||||
|
child: bar(cupertino: cupertino, count: 3, selected: 0),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byType(FloatingDestinationBar),
|
||||||
|
matching: find.byType(GlassPill),
|
||||||
|
),
|
||||||
|
findsNWidgets(3),
|
||||||
|
);
|
||||||
|
for (var index = 0; index < 3; index += 1) {
|
||||||
|
final circle = button(tester, index);
|
||||||
|
expect(circle.size, Size(diameter, diameter));
|
||||||
|
expect(
|
||||||
|
tester
|
||||||
|
.widget<GlassPill>(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byKey(tabKey(index)),
|
||||||
|
matching: find.byType(GlassPill),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.shape,
|
||||||
|
isA<CircleBorder>(),
|
||||||
|
);
|
||||||
|
final icon = tester.getRect(find.byIcon(icons[index]));
|
||||||
|
expect(icon.size, Size(iconSize, iconSize));
|
||||||
|
expect(icon.center, circle.center);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (final placement in placements) {
|
||||||
|
testWidgets('$host ${placement.name}: a row at the bottom right, '
|
||||||
|
'evenly spaced', (tester) async {
|
||||||
|
final count = placement.count;
|
||||||
|
final size = placement.size;
|
||||||
|
await pump(
|
||||||
|
tester,
|
||||||
|
cupertino: cupertino,
|
||||||
|
size: size,
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.bottomCenter,
|
||||||
|
child: bar(cupertino: cupertino, count: count, selected: 0),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final box = row(tester);
|
||||||
|
expect(box.right, size.width - 16);
|
||||||
|
expect(box.bottom, size.height - 16);
|
||||||
|
expect(box.height, diameter);
|
||||||
|
expect(
|
||||||
|
box.width,
|
||||||
|
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: count),
|
||||||
|
);
|
||||||
|
expect(button(tester, 0).left, box.left);
|
||||||
|
expect(button(tester, count - 1).right, box.right);
|
||||||
|
for (var index = 1; index < count; index += 1) {
|
||||||
|
expect(
|
||||||
|
button(tester, index).left - button(tester, index - 1).right,
|
||||||
|
moreOrLessEquals(gap),
|
||||||
|
);
|
||||||
|
expect(button(tester, index).top, box.top);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets('$host: taps between and beside the buttons reach the '
|
||||||
|
'content, taps on them 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 = row(tester);
|
||||||
|
expect(box.width, lessThan(390 / 2));
|
||||||
|
await tester.tapAt(Offset(box.left - 40, box.center.dy));
|
||||||
|
final between = (button(tester, 0).right + button(tester, 1).left) / 2;
|
||||||
|
await tester.tapAt(Offset(between, box.center.dy));
|
||||||
|
await tester.tapAt(button(tester, 0).center);
|
||||||
|
await tester.tapAt(button(tester, 2).center);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(content, 2);
|
||||||
|
expect(tapped, [0, 2]);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('$host: 5 tabs at 320 with 2x text narrow their gaps and '
|
||||||
|
'stay within the margins', (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);
|
||||||
|
final box = row(tester);
|
||||||
|
expect(box.right, 320 - 16);
|
||||||
|
expect(box.left, greaterThanOrEqualTo(16));
|
||||||
|
final narrowed = (288 - 5 * diameter) / 4;
|
||||||
|
for (var index = 1; index < 5; index += 1) {
|
||||||
|
expect(button(tester, index).width, diameter);
|
||||||
|
expect(
|
||||||
|
button(tester, index).left - button(tester, index - 1).right,
|
||||||
|
moreOrLessEquals(narrowed < gap ? narrowed : gap),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('$host: right to left, the row sits at the bottom left and '
|
||||||
|
'reads from the right', (tester) async {
|
||||||
|
await pump(
|
||||||
|
tester,
|
||||||
|
cupertino: cupertino,
|
||||||
|
size: const Size(390, 844),
|
||||||
|
child: Directionality(
|
||||||
|
textDirection: TextDirection.rtl,
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.bottomCenter,
|
||||||
|
child: bar(cupertino: cupertino, count: 3, selected: 0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(row(tester).left, 16);
|
||||||
|
expect(button(tester, 0).right, row(tester).right);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,7 +49,7 @@ void main() {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final pill = tester.getRect(find.byType(GlassPill));
|
final pill = tester.getRect(find.byKey(FloatingDestinationBar.rowKey));
|
||||||
// The list fills the area, behind the bar.
|
// The list fills the area, behind the bar.
|
||||||
expect(tester.getRect(find.byType(ListView)).bottom, 800);
|
expect(tester.getRect(find.byType(ListView)).bottom, 800);
|
||||||
await tester.drag(find.byType(ListView), const Offset(0, -5000));
|
await tester.drag(find.byType(ListView), const Offset(0, -5000));
|
||||||
@@ -67,11 +67,11 @@ void main() {
|
|||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
page(list: (_) => const SizedBox.expand(), onTap: () => taps++),
|
page(list: (_) => const SizedBox.expand(), onTap: () => taps++),
|
||||||
);
|
);
|
||||||
final pill = tester.getRect(find.byType(GlassPill));
|
final pill = tester.getRect(find.byKey(FloatingDestinationBar.rowKey));
|
||||||
expect(pill.right, 1200 - kFloatingBarMargin);
|
expect(pill.right, 1200 - kFloatingBarMargin);
|
||||||
await tester.tapAt(Offset(pill.left - 24, pill.center.dy));
|
await tester.tapAt(Offset(pill.left - 24, pill.center.dy));
|
||||||
expect(taps, 1);
|
expect(taps, 1);
|
||||||
await tester.tapAt(pill.center);
|
await tester.tapAt(tester.getCenter(find.byType(GlassPill).first));
|
||||||
expect(taps, 1, reason: 'the bar takes its own taps');
|
expect(taps, 1, reason: 'the bar takes its own taps');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,13 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||||
import 'package:pipelines_app/shell/destination.dart';
|
import 'package:pipelines_app/shell/destination.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||||
|
import 'package:pipelines_app/ui/adaptive/floating_tab_button.dart';
|
||||||
|
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||||
|
|
||||||
/// The floating tab bar's motion: the tabs pop in only when the bar appears
|
/// The floating tab bar's motion: each button pops in on its own, staggered,
|
||||||
/// or its set of tabs changes, and one selection highlight glides (and
|
/// only when the bar appears or its set of tabs changes; the selection tint
|
||||||
/// stretches on the way) to a newly selected tab, whose icon bounces.
|
/// cross-fades to a newly selected button, whose icon bounces; a press sinks
|
||||||
|
/// the button and it springs back.
|
||||||
void main() {
|
void main() {
|
||||||
const icons = [
|
const icons = [
|
||||||
Icons.account_tree_outlined,
|
Icons.account_tree_outlined,
|
||||||
@@ -30,15 +33,16 @@ void main() {
|
|||||||
void animate(WidgetTester tester, {required bool on}) {
|
void animate(WidgetTester tester, {required bool on}) {
|
||||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||||
FakeAccessibilityFeatures(disableAnimations: !on);
|
FakeAccessibilityFeatures(disableAnimations: !on);
|
||||||
addTearDown(() {
|
addTearDown(tester.platformDispatcher.clearAccessibilityFeaturesTestValue);
|
||||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
|
||||||
const FakeAccessibilityFeatures(disableAnimations: true);
|
|
||||||
});
|
|
||||||
tester.view.physicalSize = const Size(560, 900);
|
tester.view.physicalSize = const Size(560, 900);
|
||||||
tester.view.devicePixelRatio = 1;
|
tester.view.devicePixelRatio = 1;
|
||||||
addTearDown(tester.view.reset);
|
addTearDown(tester.view.reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget app(bool cupertino, Widget body) => cupertino
|
||||||
|
? CupertinoApp(home: CupertinoPageScaffold(child: body))
|
||||||
|
: MaterialApp(home: Scaffold(body: body));
|
||||||
|
|
||||||
/// A bar of [count] tabs whose tap selects.
|
/// A bar of [count] tabs whose tap selects.
|
||||||
Future<void> pumpBar(
|
Future<void> pumpBar(
|
||||||
WidgetTester tester, {
|
WidgetTester tester, {
|
||||||
@@ -46,74 +50,92 @@ void main() {
|
|||||||
int count = 3,
|
int count = 3,
|
||||||
}) async {
|
}) async {
|
||||||
var selected = 0;
|
var selected = 0;
|
||||||
final body = StatefulBuilder(
|
|
||||||
builder: (context, setState) {
|
|
||||||
return Align(
|
|
||||||
alignment: Alignment.bottomCenter,
|
|
||||||
child: FloatingDestinationBar(
|
|
||||||
cupertino: cupertino,
|
|
||||||
currentIndex: selected,
|
|
||||||
onTap: (index) => setState(() => selected = index),
|
|
||||||
items: items(count),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
cupertino
|
app(
|
||||||
? CupertinoApp(home: CupertinoPageScaffold(child: body))
|
cupertino,
|
||||||
: MaterialApp(home: Scaffold(body: body)),
|
StatefulBuilder(
|
||||||
|
builder: (context, setState) => Align(
|
||||||
|
alignment: Alignment.bottomCenter,
|
||||||
|
child: FloatingDestinationBar(
|
||||||
|
cupertino: cupertino,
|
||||||
|
currentIndex: selected,
|
||||||
|
onTap: (index) => setState(() => selected = index),
|
||||||
|
items: items(count),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The opacity of [tab]'s entrance fade.
|
Finder glass(Finder tab) =>
|
||||||
double opacityOf(WidgetTester tester, Finder tab) => tester
|
find.descendant(of: tab, matching: find.byType(GlassPill));
|
||||||
.widget<FadeTransition>(
|
|
||||||
find
|
|
||||||
.descendant(
|
|
||||||
of: tab,
|
|
||||||
matching: find.byWidgetPredicate(
|
|
||||||
(widget) =>
|
|
||||||
widget is FadeTransition && widget.child is AnimatedBuilder,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.last,
|
|
||||||
)
|
|
||||||
.opacity
|
|
||||||
.value;
|
|
||||||
|
|
||||||
double iconWidth(WidgetTester tester, Finder tab, IconData icon) => tester
|
/// The opacity of [tab]'s entrance fade (its glass reveal).
|
||||||
.getRect(find.descendant(of: tab, matching: find.byIcon(icon)))
|
double opacityOf(WidgetTester tester, Finder tab) =>
|
||||||
|
GlassReveal.maybeOf(tester.element(glass(tab)))?.value ?? 1;
|
||||||
|
|
||||||
|
/// [tab]'s drawn width (its entrance and press scale it).
|
||||||
|
double widthOf(WidgetTester tester, Finder tab) =>
|
||||||
|
tester.getRect(glass(tab)).width;
|
||||||
|
|
||||||
|
double iconWidth(WidgetTester tester, int index) => tester
|
||||||
|
.getRect(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byKey(tabKey(index)),
|
||||||
|
matching: find.byIcon(icons[index]),
|
||||||
|
),
|
||||||
|
)
|
||||||
.width;
|
.width;
|
||||||
|
|
||||||
Rect highlight(WidgetTester tester) => tester.getRect(
|
/// The alpha of tab [index]'s selection fill.
|
||||||
find.descendant(
|
double fillAlpha(WidgetTester tester, int index) {
|
||||||
of: find.byKey(FloatingDestinationBar.highlightKey),
|
final fill = tester.widget(
|
||||||
matching: find.byType(DecoratedBox),
|
find.descendant(
|
||||||
),
|
of: find.byKey(tabKey(index)),
|
||||||
);
|
matching: find.byKey(FloatingTabButton.fillKey),
|
||||||
|
),
|
||||||
Offset iconCentre(WidgetTester tester, int index) => tester.getCenter(
|
);
|
||||||
find.descendant(
|
final decoration = fill is Ink
|
||||||
of: find.byKey(tabKey(index)),
|
? fill.decoration
|
||||||
matching: find.byIcon(icons[index]),
|
: (fill as DecoratedBox).decoration;
|
||||||
),
|
return (decoration! as ShapeDecoration).color!.a;
|
||||||
);
|
}
|
||||||
|
|
||||||
for (final cupertino in [false, true]) {
|
for (final cupertino in [false, true]) {
|
||||||
final host = cupertino ? 'Cupertino' : 'Material';
|
final host = cupertino ? 'Cupertino' : 'Material';
|
||||||
|
final size = FloatingDestinationBar.buttonSize(cupertino: cupertino);
|
||||||
final iconSize = cupertino
|
final iconSize = cupertino
|
||||||
? FloatingDestinationBar.cupertinoIconSize
|
? FloatingDestinationBar.cupertinoIconSize
|
||||||
: FloatingDestinationBar.materialIconSize;
|
: FloatingDestinationBar.materialIconSize;
|
||||||
final size = cupertino
|
|
||||||
? FloatingDestinationBar.cupertinoHighlightSize
|
|
||||||
: FloatingDestinationBar.materialHighlightSize;
|
|
||||||
|
|
||||||
testWidgets('$host: the entrance does not replay when the selection '
|
testWidgets('$host: each button pops in on its own, staggered, from '
|
||||||
'changes, and plays again for a new set of tabs', (tester) async {
|
'0.6 to full size', (tester) async {
|
||||||
|
animate(tester, on: true);
|
||||||
|
await pumpBar(tester, cupertino: cupertino);
|
||||||
|
for (var index = 0; index < 3; index += 1) {
|
||||||
|
final tab = find.byKey(tabKey(index));
|
||||||
|
expect(opacityOf(tester, tab), 0);
|
||||||
|
expect(widthOf(tester, tab), moreOrLessEquals(size * 0.6));
|
||||||
|
}
|
||||||
|
await tester.pump(const Duration(milliseconds: 130));
|
||||||
|
final first = widthOf(tester, find.byKey(tabKey(0)));
|
||||||
|
final last = widthOf(tester, find.byKey(tabKey(2)));
|
||||||
|
expect(first, greaterThan(last + 4), reason: 'staggered');
|
||||||
|
expect(opacityOf(tester, find.byKey(tabKey(0))), greaterThan(0.9));
|
||||||
|
expect(opacityOf(tester, find.byKey(tabKey(2))), lessThan(0.2));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
for (var index = 0; index < 3; index += 1) {
|
||||||
|
final tab = find.byKey(tabKey(index));
|
||||||
|
expect(opacityOf(tester, tab), 1);
|
||||||
|
expect(widthOf(tester, tab), size);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('$host: the entrance does not replay when the selection '
|
||||||
|
'changes', (tester) async {
|
||||||
animate(tester, on: true);
|
animate(tester, on: true);
|
||||||
await pumpBar(tester, cupertino: cupertino);
|
await pumpBar(tester, cupertino: cupertino);
|
||||||
expect(opacityOf(tester, find.byKey(tabKey(0))), 0);
|
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
for (final target in [1, 2, 0]) {
|
for (final target in [1, 2, 0]) {
|
||||||
await tester.tap(find.byKey(tabKey(target)));
|
await tester.tap(find.byKey(tabKey(target)));
|
||||||
@@ -122,14 +144,18 @@ void main() {
|
|||||||
for (var index = 0; index < 3; index += 1) {
|
for (var index = 0; index < 3; index += 1) {
|
||||||
final tab = find.byKey(tabKey(index));
|
final tab = find.byKey(tabKey(index));
|
||||||
expect(opacityOf(tester, tab), 1, reason: 'tab $index faded');
|
expect(opacityOf(tester, tab), 1, reason: 'tab $index faded');
|
||||||
// Only the bounce may grow an icon; a replayed pop shrinks it.
|
// Only the press may shrink the tapped button, and only a
|
||||||
|
// little; a replayed pop starts at 0.6.
|
||||||
expect(
|
expect(
|
||||||
iconWidth(tester, tab, icons[index]),
|
widthOf(tester, tab),
|
||||||
greaterThanOrEqualTo(iconSize - 0.01),
|
index == target
|
||||||
|
? greaterThan(size * 0.9)
|
||||||
|
: moreOrLessEquals(size),
|
||||||
reason: 'tab $index popped again',
|
reason: 'tab $index popped again',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
await tester.pumpAndSettle();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -137,24 +163,24 @@ void main() {
|
|||||||
animate(tester, on: true);
|
animate(tester, on: true);
|
||||||
var count = 3;
|
var count = 3;
|
||||||
late StateSetter update;
|
late StateSetter update;
|
||||||
Widget build() => StatefulBuilder(
|
|
||||||
builder: (context, setState) {
|
|
||||||
update = setState;
|
|
||||||
return Align(
|
|
||||||
alignment: Alignment.bottomCenter,
|
|
||||||
child: FloatingDestinationBar(
|
|
||||||
cupertino: cupertino,
|
|
||||||
currentIndex: 0,
|
|
||||||
onTap: (_) {},
|
|
||||||
items: items(count),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
cupertino
|
app(
|
||||||
? CupertinoApp(home: CupertinoPageScaffold(child: build()))
|
cupertino,
|
||||||
: MaterialApp(home: Scaffold(body: build())),
|
StatefulBuilder(
|
||||||
|
builder: (context, setState) {
|
||||||
|
update = setState;
|
||||||
|
return Align(
|
||||||
|
alignment: Alignment.bottomCenter,
|
||||||
|
child: FloatingDestinationBar(
|
||||||
|
cupertino: cupertino,
|
||||||
|
currentIndex: 0,
|
||||||
|
onTap: (_) {},
|
||||||
|
items: items(count),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(opacityOf(tester, find.byKey(tabKey(2))), 1);
|
expect(opacityOf(tester, find.byKey(tabKey(2))), 1);
|
||||||
@@ -164,84 +190,80 @@ void main() {
|
|||||||
expect(opacityOf(tester, find.byKey(tabKey(2))), 0);
|
expect(opacityOf(tester, find.byKey(tabKey(2))), 0);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(opacityOf(tester, find.byKey(tabKey(3))), 1);
|
expect(opacityOf(tester, find.byKey(tabKey(3))), 1);
|
||||||
|
expect(widthOf(tester, find.byKey(tabKey(3))), size);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('$host: the highlight rests on the selected tab as the old '
|
testWidgets('$host: the selection tint cross-fades to the new button, '
|
||||||
'circle did, glides and stretches between tabs, and the new icon '
|
'whose icon takes the selected colour and bounces', (tester) async {
|
||||||
'bounces', (tester) async {
|
|
||||||
animate(tester, on: true);
|
animate(tester, on: true);
|
||||||
await pumpBar(tester, cupertino: cupertino);
|
await pumpBar(tester, cupertino: cupertino);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(
|
final tint = fillAlpha(tester, 0);
|
||||||
highlight(tester),
|
expect(tint, greaterThan(0.1));
|
||||||
rectMoreOrLessEquals(
|
expect(fillAlpha(tester, 1), 0);
|
||||||
Rect.fromCenter(
|
expect(fillAlpha(tester, 2), 0);
|
||||||
center: iconCentre(tester, 0),
|
|
||||||
width: size,
|
|
||||||
height: size,
|
|
||||||
),
|
|
||||||
epsilon: 0.01,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(find.byKey(FloatingDestinationBar.highlightKey), findsOneWidget);
|
|
||||||
|
|
||||||
await tester.tap(find.byKey(tabKey(2)));
|
await tester.tap(find.byKey(tabKey(2)));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
await tester.pump(const Duration(milliseconds: 60));
|
await tester.pump(const Duration(milliseconds: 80));
|
||||||
final from = iconCentre(tester, 0).dx;
|
expect(fillAlpha(tester, 2), inExclusiveRange(0, tint));
|
||||||
final to = iconCentre(tester, 2).dx;
|
expect(fillAlpha(tester, 0), inExclusiveRange(0, tint));
|
||||||
final moving = highlight(tester);
|
// The icon grows within its button (which the tap's press sinks).
|
||||||
expect(moving.center.dx, greaterThan(from + 1));
|
|
||||||
expect(moving.center.dx, lessThan(to - 1));
|
|
||||||
expect(moving.height, moreOrLessEquals(size));
|
|
||||||
expect(moving.width, greaterThan(size * 1.1));
|
|
||||||
expect(moving.width, lessThanOrEqualTo(size * 1.25 + 0.01));
|
|
||||||
expect(
|
expect(
|
||||||
iconWidth(tester, find.byKey(tabKey(2)), icons[2]),
|
iconWidth(tester, 2) * size / widthOf(tester, find.byKey(tabKey(2))),
|
||||||
greaterThan(iconSize * 1.02),
|
greaterThan(iconSize * 1.04),
|
||||||
);
|
);
|
||||||
|
expect(iconWidth(tester, 1), moreOrLessEquals(iconSize));
|
||||||
|
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
expect(fillAlpha(tester, 2), tint);
|
||||||
|
expect(fillAlpha(tester, 0), 0);
|
||||||
|
expect(iconWidth(tester, 2), moreOrLessEquals(iconSize));
|
||||||
|
final context = tester.element(find.byKey(tabKey(2)));
|
||||||
|
final selectedColour = cupertino
|
||||||
|
? CupertinoTheme.of(context).primaryColor
|
||||||
|
: Theme.of(context).colorScheme.onSecondaryContainer;
|
||||||
expect(
|
expect(
|
||||||
highlight(tester),
|
IconTheme.of(tester.element(find.byIcon(icons[2]))).color,
|
||||||
rectMoreOrLessEquals(
|
isSameColorAs(selectedColour),
|
||||||
Rect.fromCenter(
|
|
||||||
center: iconCentre(tester, 2),
|
|
||||||
width: size,
|
|
||||||
height: size,
|
|
||||||
),
|
|
||||||
epsilon: 0.01,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
iconWidth(tester, find.byKey(tabKey(2)), icons[2]),
|
IconTheme.of(tester.element(find.byIcon(icons[0]))).color,
|
||||||
moreOrLessEquals(iconSize),
|
isNot(isSameColorAs(selectedColour)),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('$host: under reduced motion the highlight jumps and the '
|
testWidgets('$host: a press sinks the button and it springs back', (
|
||||||
'icons neither pop nor bounce', (tester) async {
|
tester,
|
||||||
|
) async {
|
||||||
|
animate(tester, on: true);
|
||||||
|
await pumpBar(tester, cupertino: cupertino);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
final tab = find.byKey(tabKey(1));
|
||||||
|
final gesture = await tester.startGesture(tester.getCenter(tab));
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(const Duration(milliseconds: 120));
|
||||||
|
expect(widthOf(tester, tab), lessThan(size * 0.97));
|
||||||
|
expect(widthOf(tester, find.byKey(tabKey(0))), size);
|
||||||
|
await gesture.up();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(widthOf(tester, tab), size);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('$host: under reduced motion the tint jumps and the buttons '
|
||||||
|
'neither pop nor bounce', (tester) async {
|
||||||
animate(tester, on: false);
|
animate(tester, on: false);
|
||||||
await pumpBar(tester, cupertino: cupertino);
|
await pumpBar(tester, cupertino: cupertino);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(opacityOf(tester, find.byKey(tabKey(1))), 1);
|
expect(opacityOf(tester, find.byKey(tabKey(1))), 1);
|
||||||
|
expect(widthOf(tester, find.byKey(tabKey(1))), size);
|
||||||
|
final tint = fillAlpha(tester, 0);
|
||||||
await tester.tap(find.byKey(tabKey(2)));
|
await tester.tap(find.byKey(tabKey(2)));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(
|
await tester.pump();
|
||||||
highlight(tester),
|
expect(fillAlpha(tester, 2), tint);
|
||||||
rectMoreOrLessEquals(
|
expect(fillAlpha(tester, 0), 0);
|
||||||
Rect.fromCenter(
|
expect(iconWidth(tester, 2), moreOrLessEquals(iconSize));
|
||||||
center: iconCentre(tester, 2),
|
|
||||||
width: size,
|
|
||||||
height: size,
|
|
||||||
),
|
|
||||||
epsilon: 0.01,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
iconWidth(tester, find.byKey(tabKey(2)), icons[2]),
|
|
||||||
moreOrLessEquals(iconSize),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('$host: switching the shell tabs never replays the main '
|
testWidgets('$host: switching the shell tabs never replays the main '
|
||||||
@@ -270,14 +292,17 @@ void main() {
|
|||||||
for (var frame = 0; frame < 12; frame += 1) {
|
for (var frame = 0; frame < 12; frame += 1) {
|
||||||
await tester.pump(const Duration(milliseconds: 25));
|
await tester.pump(const Duration(milliseconds: 25));
|
||||||
for (final tab in shellTabDestinations) {
|
for (final tab in shellTabDestinations) {
|
||||||
|
final finder = find.byKey(
|
||||||
|
ValueKey('shell.destination.${tab.name}'),
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
opacityOf(
|
opacityOf(tester, finder),
|
||||||
tester,
|
|
||||||
find.byKey(ValueKey('shell.destination.${tab.name}')),
|
|
||||||
),
|
|
||||||
1,
|
1,
|
||||||
reason: '${tab.name} faded switching to ${next.name}',
|
reason: '${tab.name} faded switching to ${next.name}',
|
||||||
);
|
);
|
||||||
|
if (tab != next) {
|
||||||
|
expect(widthOf(tester, finder), size, reason: tab.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:ui' show SemanticsRole;
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
@@ -63,32 +65,58 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
final floating = find.byType(FloatingDestinationBar);
|
final floating = find.byType(FloatingDestinationBar);
|
||||||
if (cupertino) {
|
// No label is drawn at all.
|
||||||
// No label is drawn at all.
|
expect(
|
||||||
expect(
|
find.descendant(of: floating, matching: find.byType(Text)),
|
||||||
find.descendant(of: floating, matching: find.byType(Text)),
|
findsNothing,
|
||||||
findsNothing,
|
);
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// NavigationBar keeps its label hidden (for semantics only).
|
|
||||||
expect(
|
|
||||||
NavigationBarTheme.of(
|
|
||||||
tester.element(find.byType(NavigationDestination).first),
|
|
||||||
).labelBehavior,
|
|
||||||
NavigationDestinationLabelBehavior.alwaysHide,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for (final (index, (key, tabLabel)) in tabs.indexed) {
|
for (final (index, (key, tabLabel)) in tabs.indexed) {
|
||||||
final node = tester.getSemantics(find.byKey(ValueKey(key)));
|
final finder = find.byKey(ValueKey(key));
|
||||||
|
final node = tester.getSemantics(finder);
|
||||||
expect(node.label, startsWith(tabLabel), reason: key);
|
expect(node.label, startsWith(tabLabel), reason: key);
|
||||||
expect(
|
expect(
|
||||||
node,
|
node,
|
||||||
index == 0
|
isSemantics(
|
||||||
? isSemantics(isSelected: true)
|
isSelected: index == 0,
|
||||||
: isNot(isSemantics(isSelected: true)),
|
hasSelectedState: true,
|
||||||
|
isButton: true,
|
||||||
|
hasTapAction: true,
|
||||||
|
),
|
||||||
reason: key,
|
reason: key,
|
||||||
);
|
);
|
||||||
|
expect(node.role, SemanticsRole.tab, reason: key);
|
||||||
|
// "Tab n of m", as the host navigation controls announce it: in the
|
||||||
|
// Material label, the Cupertino hint.
|
||||||
|
final position = 'Tab ${index + 1} of ${tabs.length}';
|
||||||
|
expect(
|
||||||
|
cupertino ? node.hint : node.label,
|
||||||
|
contains(position),
|
||||||
|
reason: key,
|
||||||
|
);
|
||||||
|
// Material names the tab in its tooltip too.
|
||||||
|
if (!cupertino) {
|
||||||
|
expect(
|
||||||
|
find.descendant(
|
||||||
|
of: finder,
|
||||||
|
matching: find.byWidgetPredicate(
|
||||||
|
(widget) => widget is Tooltip && widget.message == tabLabel,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
findsOneWidget,
|
||||||
|
reason: key,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// A hit target at least the platform minimum.
|
||||||
|
expect(
|
||||||
|
tester.getSize(finder).shortestSide,
|
||||||
|
greaterThanOrEqualTo(cupertino ? 44 : 48),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
// The tabs make up one tab bar.
|
||||||
|
final tabBar = tester.getSemantics(
|
||||||
|
find.byKey(FloatingDestinationBar.rowKey),
|
||||||
|
);
|
||||||
|
expect(tabBar.role, SemanticsRole.tabBar);
|
||||||
// Distinct glyphs within the bar.
|
// Distinct glyphs within the bar.
|
||||||
final icons = tester
|
final icons = tester
|
||||||
.widgetList<Icon>(
|
.widgetList<Icon>(
|
||||||
|
|||||||
@@ -184,10 +184,10 @@ void main() {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final pill = tester.getRect(find.byType(GlassPill));
|
final pill = tester.getRect(find.byKey(FloatingDestinationBar.rowKey));
|
||||||
expect(pill.top, 64);
|
expect(pill.top, 64);
|
||||||
// The pill is the bar's own height: leftover media padding is not added.
|
// The pill is the bar's own height: leftover media padding is not added.
|
||||||
expect(pill.height, FloatingDestinationBar.materialHeight);
|
expect(pill.height, FloatingDestinationBar.materialButtonSize);
|
||||||
// Wide: sized to its tabs at the leading edge, under the title.
|
// Wide: sized to its tabs at the leading edge, under the title.
|
||||||
expect(pill.left, FloatingDestinationBar.topMargin);
|
expect(pill.left, FloatingDestinationBar.topMargin);
|
||||||
expect(pill.width, lessThan(400));
|
expect(pill.width, lessThan(400));
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
|
|
||||||
import 'package:pipelines_app/main.dart';
|
import 'package:pipelines_app/main.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
||||||
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
for (final width in [390.0, 1000.0]) {
|
for (final width in [390.0, 1000.0]) {
|
||||||
@@ -25,7 +26,7 @@ void main() {
|
|||||||
expect(find.text('Pipelines'), findsWidgets);
|
expect(find.text('Pipelines'), findsWidgets);
|
||||||
expect(find.text('Pipelines — Not implemented'), findsOneWidget);
|
expect(find.text('Pipelines — Not implemented'), findsOneWidget);
|
||||||
// One floating tab bar at every width; no rail.
|
// One floating tab bar at every width; no rail.
|
||||||
expect(find.byType(NavigationBar), findsOneWidget);
|
expect(find.byType(FloatingDestinationBar), findsOneWidget);
|
||||||
expect(find.byType(NavigationRail), findsNothing);
|
expect(find.byType(NavigationRail), findsNothing);
|
||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
|
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
|
||||||
@@ -45,7 +46,7 @@ void main() {
|
|||||||
await tester.pumpWidget(const MyApp(cupertino: true));
|
await tester.pumpWidget(const MyApp(cupertino: true));
|
||||||
expect(find.byType(SegmentedBar), findsOneWidget);
|
expect(find.byType(SegmentedBar), findsOneWidget);
|
||||||
expect(find.byType(CupertinoNavigationBar), findsNothing);
|
expect(find.byType(CupertinoNavigationBar), findsNothing);
|
||||||
expect(find.byType(CupertinoTabBar), findsOneWidget);
|
expect(find.byType(FloatingDestinationBar), findsOneWidget);
|
||||||
expect(find.text('Pipelines — Not implemented'), findsOneWidget);
|
expect(find.text('Pipelines — Not implemented'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ void main() {
|
|||||||
addTearDown(tester.view.resetPhysicalSize);
|
addTearDown(tester.view.resetPhysicalSize);
|
||||||
addTearDown(tester.view.resetDevicePixelRatio);
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
await tester.pumpWidget(const MyApp(cupertino: true));
|
await tester.pumpWidget(const MyApp(cupertino: true));
|
||||||
expect(find.byType(CupertinoTabBar), findsOneWidget);
|
expect(find.byType(FloatingDestinationBar), findsOneWidget);
|
||||||
expect(find.byType(CupertinoListTile), findsNothing);
|
expect(find.byType(CupertinoListTile), findsNothing);
|
||||||
expect(
|
expect(
|
||||||
find.byKey(const ValueKey('shell.destination.pipelines')),
|
find.byKey(const ValueKey('shell.destination.pipelines')),
|
||||||
@@ -76,7 +77,7 @@ void main() {
|
|||||||
tester.view.padding = const FakeViewPadding(top: 36, bottom: 28);
|
tester.view.padding = const FakeViewPadding(top: 36, bottom: 28);
|
||||||
addTearDown(tester.view.resetPadding);
|
addTearDown(tester.view.resetPadding);
|
||||||
await tester.pumpWidget(const MyApp(cupertino: true));
|
await tester.pumpWidget(const MyApp(cupertino: true));
|
||||||
final tabBar = tester.getRect(find.byType(CupertinoTabBar));
|
final tabBar = tester.getRect(find.byType(FloatingDestinationBar));
|
||||||
expect(tabBar.bottom, lessThanOrEqualTo(900 - 28));
|
expect(tabBar.bottom, lessThanOrEqualTo(900 - 28));
|
||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user