Unverified Commit bfa4bdbf authored by Yash Johri's avatar Yash Johri Committed by GitHub

[SwitchListTile] Adds hoverColor to SwitchListTile (#91046)

parent 0a3ae081
...@@ -146,6 +146,7 @@ class SwitchListTile extends StatelessWidget { ...@@ -146,6 +146,7 @@ class SwitchListTile extends StatelessWidget {
this.visualDensity, this.visualDensity,
this.focusNode, this.focusNode,
this.enableFeedback, this.enableFeedback,
this.hoverColor,
}) : _switchListTileType = _SwitchListTileType.material, }) : _switchListTileType = _SwitchListTileType.material,
assert(value != null), assert(value != null),
assert(isThreeLine != null), assert(isThreeLine != null),
...@@ -191,6 +192,7 @@ class SwitchListTile extends StatelessWidget { ...@@ -191,6 +192,7 @@ class SwitchListTile extends StatelessWidget {
this.visualDensity, this.visualDensity,
this.focusNode, this.focusNode,
this.enableFeedback, this.enableFeedback,
this.hoverColor,
}) : _switchListTileType = _SwitchListTileType.adaptive, }) : _switchListTileType = _SwitchListTileType.adaptive,
assert(value != null), assert(value != null),
assert(isThreeLine != null), assert(isThreeLine != null),
...@@ -342,6 +344,9 @@ class SwitchListTile extends StatelessWidget { ...@@ -342,6 +344,9 @@ class SwitchListTile extends StatelessWidget {
/// * [Feedback] for providing platform-specific feedback to certain actions. /// * [Feedback] for providing platform-specific feedback to certain actions.
final bool? enableFeedback; final bool? enableFeedback;
/// The color for the tile's [Material] when a pointer is hovering over it.
final Color? hoverColor;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Widget control; final Widget control;
...@@ -410,6 +415,7 @@ class SwitchListTile extends StatelessWidget { ...@@ -410,6 +415,7 @@ class SwitchListTile extends StatelessWidget {
visualDensity: visualDensity, visualDensity: visualDensity,
focusNode: focusNode, focusNode: focusNode,
enableFeedback: enableFeedback, enableFeedback: enableFeedback,
hoverColor: hoverColor,
), ),
), ),
); );
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -519,4 +520,45 @@ void main() { ...@@ -519,4 +520,45 @@ void main() {
expect(feedback.hapticCount, 0); 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),
)
);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment