From bfa4bdbf3b28b0148b72ee3620e8b24e39d33de7 Mon Sep 17 00:00:00 2001 From: Yash Johri Date: Fri, 8 Oct 2021 04:48:05 +0530 Subject: [PATCH] [SwitchListTile] Adds hoverColor to SwitchListTile (#91046) --- .../lib/src/material/switch_list_tile.dart | 6 +++ .../test/material/switch_list_tile_test.dart | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/packages/flutter/lib/src/material/switch_list_tile.dart b/packages/flutter/lib/src/material/switch_list_tile.dart index 2caf4d34c43..a9a7bf91bf5 100644 --- a/packages/flutter/lib/src/material/switch_list_tile.dart +++ b/packages/flutter/lib/src/material/switch_list_tile.dart @@ -146,6 +146,7 @@ class SwitchListTile extends StatelessWidget { this.visualDensity, this.focusNode, this.enableFeedback, + this.hoverColor, }) : _switchListTileType = _SwitchListTileType.material, assert(value != null), assert(isThreeLine != null), @@ -191,6 +192,7 @@ class SwitchListTile extends StatelessWidget { this.visualDensity, this.focusNode, this.enableFeedback, + this.hoverColor, }) : _switchListTileType = _SwitchListTileType.adaptive, assert(value != null), assert(isThreeLine != null), @@ -342,6 +344,9 @@ class SwitchListTile extends StatelessWidget { /// * [Feedback] for providing platform-specific feedback to certain actions. final bool? enableFeedback; + /// The color for the tile's [Material] when a pointer is hovering over it. + final Color? hoverColor; + @override Widget build(BuildContext context) { final Widget control; @@ -410,6 +415,7 @@ class SwitchListTile extends StatelessWidget { visualDensity: visualDensity, focusNode: focusNode, enableFeedback: enableFeedback, + hoverColor: hoverColor, ), ), ); diff --git a/packages/flutter/test/material/switch_list_tile_test.dart b/packages/flutter/test/material/switch_list_tile_test.dart index 84bec80fcb7..74121e7dbbf 100644 --- a/packages/flutter/test/material/switch_list_tile_test.dart +++ b/packages/flutter/test/material/switch_list_tile_test.dart @@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -519,4 +520,45 @@ void main() { expect(feedback.hapticCount, 0); }); }); + + testWidgets('SwitchListTile respects hoverColor', (WidgetTester tester) async { + const Key key = Key('test'); + await tester.pumpWidget( + wrap( + child: Center( + child: StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + return Container( + width: 100, + height: 100, + color: Colors.white, + child: SwitchListTile( + value: false, + key: key, + hoverColor: Colors.orange[500], + title: const Text('A'), + onChanged: (bool? value) {}, + ), + ); + }), + ), + ), + ); + + // Start hovering + final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); + addTearDown(gesture.removePointer); + await gesture.moveTo(tester.getCenter(find.byKey(key))); + + await tester.pump(); + await tester.pumpAndSettle(); + expect( + Material.of(tester.element(find.byKey(key))), + paints + ..rect( + color: Colors.orange[500], + rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0), + ) + ); + }); }