Exposes ListTile.shape for CheckboxListTile and SwitchListTile (#67419)

This commit is contained in:
Ayush Bherwani 2020-10-07 16:22:05 -07:00 committed by GitHub
parent b3f9944f3c
commit 3517412446
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 0 deletions

View File

@ -272,6 +272,7 @@ class CheckboxListTile extends StatelessWidget {
this.autofocus = false,
this.contentPadding,
this.tristate = false,
this.shape,
}) : assert(tristate != null),
assert(tristate || value != null),
assert(isThreeLine != null),
@ -380,6 +381,9 @@ class CheckboxListTile extends StatelessWidget {
/// If tristate is false (the default), [value] must not be null.
final bool tristate;
/// {@macro flutter.material.ListTile.shape}
final ShapeBorder? shape;
void _handleValueChange() {
assert(onChanged != null);
switch (value) {
@ -433,6 +437,7 @@ class CheckboxListTile extends StatelessWidget {
selected: selected,
autofocus: autofocus,
contentPadding: contentPadding,
shape: shape,
),
),
);

View File

@ -96,7 +96,9 @@ class ListTileTheme extends InheritedTheme {
/// If true then [ListTile]s will have the vertically dense layout.
final bool dense;
/// {@template flutter.material.ListTile.shape}
/// If specified, [shape] defines the shape of the [ListTile]'s [InkWell] border.
/// {@endtemplate}
final ShapeBorder? shape;
/// If specified, [style] defines the font used for [ListTile] titles.

View File

@ -273,6 +273,7 @@ class SwitchListTile extends StatelessWidget {
this.selected = false,
this.autofocus = false,
this.controlAffinity = ListTileControlAffinity.platform,
this.shape,
}) : _switchListTileType = _SwitchListTileType.material,
assert(value != null),
assert(isThreeLine != null),
@ -308,6 +309,7 @@ class SwitchListTile extends StatelessWidget {
this.selected = false,
this.autofocus = false,
this.controlAffinity = ListTileControlAffinity.platform,
this.shape,
}) : _switchListTileType = _SwitchListTileType.adaptive,
assert(value != null),
assert(isThreeLine != null),
@ -435,6 +437,9 @@ class SwitchListTile extends StatelessWidget {
/// By default, the value of `controlAffinity` is [ListTileControlAffinity.platform].
final ListTileControlAffinity controlAffinity;
/// {@macro flutter.material.ListTile.shape}
final ShapeBorder? shape;
@override
Widget build(BuildContext context) {
Widget control;
@ -497,6 +502,7 @@ class SwitchListTile extends StatelessWidget {
onTap: onChanged != null ? () { onChanged!(!value); } : null,
selected: selected,
autofocus: autofocus,
shape: shape,
),
),
);

View File

@ -224,4 +224,21 @@ void main() {
await tester.pumpAndSettle();
expect(_value, false);
});
testWidgets('CheckboxListTile respects shape', (WidgetTester tester) async {
const ShapeBorder shapeBorder = RoundedRectangleBorder(
borderRadius: BorderRadius.horizontal(right: Radius.circular(100))
);
await tester.pumpWidget(wrap(
child: const CheckboxListTile(
value: false,
onChanged: null,
title: Text('Title'),
shape: shapeBorder,
),
));
expect(tester.widget<InkWell>(find.byType(InkWell)).customBorder, shapeBorder);
});
}

View File

@ -340,4 +340,23 @@ void main() {
expect(listTile.leading.runtimeType, Icon);
expect(listTile.trailing.runtimeType, Switch);
});
testWidgets('SwitchListTile respects shape', (WidgetTester tester) async {
const ShapeBorder shapeBorder = RoundedRectangleBorder(
borderRadius: BorderRadius.horizontal(right: Radius.circular(100))
);
await tester.pumpWidget(const MaterialApp(
home: Material(
child: SwitchListTile(
value: true,
onChanged: null,
title: Text('Title'),
shape: shapeBorder,
),
),
));
expect(tester.widget<InkWell>(find.byType(InkWell)).customBorder, shapeBorder);
});
}