mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[SwitchListTile] Adds hoverColor to SwitchListTile (#91046)
This commit is contained in:
parent
0a3ae08150
commit
bfa4bdbf3b
@ -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,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@ -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),
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user