diff --git a/packages/flutter/lib/src/material/toggle_buttons.dart b/packages/flutter/lib/src/material/toggle_buttons.dart index e0ff789b6f824..ad95bc4df478c 100644 --- a/packages/flutter/lib/src/material/toggle_buttons.dart +++ b/packages/flutter/lib/src/material/toggle_buttons.dart @@ -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, diff --git a/packages/flutter/test/material/toggle_buttons_test.dart b/packages/flutter/test/material/toggle_buttons_test.dart index 6bf2d865edb83..995fb80fff596 100644 --- a/packages/flutter/test/material/toggle_buttons_test.dart +++ b/packages/flutter/test/material/toggle_buttons_test.dart @@ -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 focusNodes = [FocusNode(), FocusNode()]; + await tester.pumpWidget( + Material( + child: boilerplate( + child: ToggleButtons( + isSelected: const [true, false], + onPressed: (int index) { }, + focusNodes: focusNodes, + children: const [Text('one'), Text('two')], + ), + ), + ), + ); + + double toggleButtonElevation(String text) { + return tester.widget(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(); + }); }