Skip to content

Commit

Permalink
ToggleButtons focus,highlight,hoverElevation = 0 (flutter#75454)
Browse files Browse the repository at this point in the history
  • Loading branch information
HansMuller authored Feb 5, 2021
1 parent da6528c commit a77388e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/flutter/lib/src/material/toggle_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -910,12 +910,13 @@ class _ToggleButton extends StatelessWidget {
),
constraints: currentConstraints,
elevation: 0.0,
highlightElevation: 0.0,
fillColor: currentFillColor,
focusColor: currentFocusColor,
highlightColor: highlightColor
?? theme.colorScheme.surface.withOpacity(0.0),
focusElevation: 0,
highlightColor: highlightColor ?? theme.colorScheme.surface.withOpacity(0.0),
highlightElevation: 0.0,
hoverColor: currentHoverColor,
hoverElevation: 0,
splashColor: currentSplashColor,
focusNode: focusNode,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
Expand Down
48 changes: 48 additions & 0 deletions packages/flutter/test/material/toggle_buttons_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1649,4 +1649,52 @@ void main() {

expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
});

testWidgets('ToggleButtons focus, hover, and highlight elevations are 0', (WidgetTester tester) async {
final List<FocusNode> focusNodes = <FocusNode>[FocusNode(), FocusNode()];
await tester.pumpWidget(
Material(
child: boilerplate(
child: ToggleButtons(
isSelected: const <bool>[true, false],
onPressed: (int index) { },
focusNodes: focusNodes,
children: const <Widget>[Text('one'), Text('two')],
),
),
),
);

double toggleButtonElevation(String text) {
return tester.widget<Material>(find.widgetWithText(Material, text).first).elevation;
}

// Default toggle button elevation
expect(toggleButtonElevation('one'), 0); // highlighted
expect(toggleButtonElevation('two'), 0); // not highlighted

// Hovered button elevation
final TestGesture hoverGesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
await hoverGesture.addPointer();
await hoverGesture.moveTo(tester.getCenter(find.text('one')));
await tester.pumpAndSettle();
expect(toggleButtonElevation('one'), 0);
await hoverGesture.moveTo(tester.getCenter(find.text('two')));
await tester.pumpAndSettle();
expect(toggleButtonElevation('two'), 0);

// Focused button elevation
focusNodes[0].requestFocus();
await tester.pumpAndSettle();
expect(focusNodes[0].hasFocus, isTrue);
expect(focusNodes[1].hasFocus, isFalse);
expect(toggleButtonElevation('one'), 0);
focusNodes[1].requestFocus();
await tester.pumpAndSettle();
expect(focusNodes[0].hasFocus, isFalse);
expect(focusNodes[1].hasFocus, isTrue);
expect(toggleButtonElevation('two'), 0);

await hoverGesture.removePointer();
});
}

0 comments on commit a77388e

Please sign in to comment.