[RadioListTile] Adds shape, tileColor and selectedTileColor to RadioListTile (#69399)
This commit is contained in:
@@ -320,7 +320,9 @@ class RadioListTile<T> extends StatelessWidget {
|
||||
this.controlAffinity = ListTileControlAffinity.platform,
|
||||
this.autofocus = false,
|
||||
this.contentPadding,
|
||||
|
||||
this.shape,
|
||||
this.tileColor,
|
||||
this.selectedTileColor,
|
||||
}) : assert(toggleable != null),
|
||||
assert(isThreeLine != null),
|
||||
assert(!isThreeLine || subtitle != null),
|
||||
@@ -483,6 +485,16 @@ class RadioListTile<T> extends StatelessWidget {
|
||||
/// To control this value, set [value] and [groupValue] appropriately.
|
||||
bool get checked => value == groupValue;
|
||||
|
||||
/// If specified, [shape] defines the shape of the [RadioListTile]'s [InkWell] border.
|
||||
final ShapeBorder? shape;
|
||||
|
||||
/// If specified, defines the background color for `RadioListTile` when
|
||||
/// [RadioListTile.selected] is false.
|
||||
final Color? tileColor;
|
||||
|
||||
/// If non-null, defines the background color when [RadioListTile.selected] is true.
|
||||
final Color? selectedTileColor;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Widget control = Radio<T>(
|
||||
@@ -517,6 +529,9 @@ class RadioListTile<T> extends StatelessWidget {
|
||||
isThreeLine: isThreeLine,
|
||||
dense: dense,
|
||||
enabled: onChanged != null,
|
||||
shape: shape,
|
||||
tileColor: tileColor,
|
||||
selectedTileColor: selectedTileColor,
|
||||
onTap: onChanged != null ? () {
|
||||
if (toggleable && checked) {
|
||||
onChanged!(null);
|
||||
|
||||
@@ -646,4 +646,67 @@ void main() {
|
||||
expect(paddingRect.left, radioRect.left - 8); //left padding
|
||||
expect(paddingRect.right, titleRect.right + 15); //right padding
|
||||
});
|
||||
|
||||
testWidgets('RadioListTile respects shape', (WidgetTester tester) async {
|
||||
const ShapeBorder shapeBorder = RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.horizontal(right: Radius.circular(100)),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(const MaterialApp(
|
||||
home: Material(
|
||||
child: RadioListTile<bool>(
|
||||
value: true,
|
||||
groupValue: true,
|
||||
onChanged: null,
|
||||
title: Text('Title'),
|
||||
shape: shapeBorder,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
expect(tester.widget<InkWell>(find.byType(InkWell)).customBorder, shapeBorder);
|
||||
});
|
||||
|
||||
testWidgets('RadioListTile respects tileColor', (WidgetTester tester) async {
|
||||
const Color tileColor = Colors.red;
|
||||
|
||||
await tester.pumpWidget(
|
||||
wrap(
|
||||
child: const Center(
|
||||
child: RadioListTile<bool>(
|
||||
value: false,
|
||||
groupValue: true,
|
||||
onChanged: null,
|
||||
title: Text('Title'),
|
||||
tileColor: tileColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
|
||||
expect(coloredBox.color, tileColor);
|
||||
});
|
||||
|
||||
testWidgets('RadioListTile respects selectedTileColor', (WidgetTester tester) async {
|
||||
const Color selectedTileColor = Colors.black;
|
||||
|
||||
await tester.pumpWidget(
|
||||
wrap(
|
||||
child: const Center(
|
||||
child: RadioListTile<bool>(
|
||||
value: false,
|
||||
groupValue: true,
|
||||
onChanged: null,
|
||||
title: Text('Title'),
|
||||
selected: true,
|
||||
selectedTileColor: selectedTileColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
|
||||
expect(coloredBox.color, equals(selectedTileColor));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user