Skip to content

Commit a77388e

Browse files
authored
ToggleButtons focus,highlight,hoverElevation = 0 (flutter#75454)
1 parent da6528c commit a77388e

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

packages/flutter/lib/src/material/toggle_buttons.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,12 +910,13 @@ class _ToggleButton extends StatelessWidget {
910910
),
911911
constraints: currentConstraints,
912912
elevation: 0.0,
913-
highlightElevation: 0.0,
914913
fillColor: currentFillColor,
915914
focusColor: currentFocusColor,
916-
highlightColor: highlightColor
917-
?? theme.colorScheme.surface.withOpacity(0.0),
915+
focusElevation: 0,
916+
highlightColor: highlightColor ?? theme.colorScheme.surface.withOpacity(0.0),
917+
highlightElevation: 0.0,
918918
hoverColor: currentHoverColor,
919+
hoverElevation: 0,
919920
splashColor: currentSplashColor,
920921
focusNode: focusNode,
921922
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,

packages/flutter/test/material/toggle_buttons_test.dart

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,4 +1649,52 @@ void main() {
16491649

16501650
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
16511651
});
1652+
1653+
testWidgets('ToggleButtons focus, hover, and highlight elevations are 0', (WidgetTester tester) async {
1654+
final List<FocusNode> focusNodes = <FocusNode>[FocusNode(), FocusNode()];
1655+
await tester.pumpWidget(
1656+
Material(
1657+
child: boilerplate(
1658+
child: ToggleButtons(
1659+
isSelected: const <bool>[true, false],
1660+
onPressed: (int index) { },
1661+
focusNodes: focusNodes,
1662+
children: const <Widget>[Text('one'), Text('two')],
1663+
),
1664+
),
1665+
),
1666+
);
1667+
1668+
double toggleButtonElevation(String text) {
1669+
return tester.widget<Material>(find.widgetWithText(Material, text).first).elevation;
1670+
}
1671+
1672+
// Default toggle button elevation
1673+
expect(toggleButtonElevation('one'), 0); // highlighted
1674+
expect(toggleButtonElevation('two'), 0); // not highlighted
1675+
1676+
// Hovered button elevation
1677+
final TestGesture hoverGesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
1678+
await hoverGesture.addPointer();
1679+
await hoverGesture.moveTo(tester.getCenter(find.text('one')));
1680+
await tester.pumpAndSettle();
1681+
expect(toggleButtonElevation('one'), 0);
1682+
await hoverGesture.moveTo(tester.getCenter(find.text('two')));
1683+
await tester.pumpAndSettle();
1684+
expect(toggleButtonElevation('two'), 0);
1685+
1686+
// Focused button elevation
1687+
focusNodes[0].requestFocus();
1688+
await tester.pumpAndSettle();
1689+
expect(focusNodes[0].hasFocus, isTrue);
1690+
expect(focusNodes[1].hasFocus, isFalse);
1691+
expect(toggleButtonElevation('one'), 0);
1692+
focusNodes[1].requestFocus();
1693+
await tester.pumpAndSettle();
1694+
expect(focusNodes[0].hasFocus, isFalse);
1695+
expect(focusNodes[1].hasFocus, isTrue);
1696+
expect(toggleButtonElevation('two'), 0);
1697+
1698+
await hoverGesture.removePointer();
1699+
});
16521700
}

0 commit comments

Comments
 (0)