Skip to content

Commit 3517412

Browse files
Exposes ListTile.shape for CheckboxListTile and SwitchListTile (flutter#67419)
1 parent b3f9944 commit 3517412

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

packages/flutter/lib/src/material/checkbox_list_tile.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ class CheckboxListTile extends StatelessWidget {
272272
this.autofocus = false,
273273
this.contentPadding,
274274
this.tristate = false,
275+
this.shape,
275276
}) : assert(tristate != null),
276277
assert(tristate || value != null),
277278
assert(isThreeLine != null),
@@ -380,6 +381,9 @@ class CheckboxListTile extends StatelessWidget {
380381
/// If tristate is false (the default), [value] must not be null.
381382
final bool tristate;
382383

384+
/// {@macro flutter.material.ListTile.shape}
385+
final ShapeBorder? shape;
386+
383387
void _handleValueChange() {
384388
assert(onChanged != null);
385389
switch (value) {
@@ -433,6 +437,7 @@ class CheckboxListTile extends StatelessWidget {
433437
selected: selected,
434438
autofocus: autofocus,
435439
contentPadding: contentPadding,
440+
shape: shape,
436441
),
437442
),
438443
);

packages/flutter/lib/src/material/list_tile.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ class ListTileTheme extends InheritedTheme {
9696
/// If true then [ListTile]s will have the vertically dense layout.
9797
final bool dense;
9898

99+
/// {@template flutter.material.ListTile.shape}
99100
/// If specified, [shape] defines the shape of the [ListTile]'s [InkWell] border.
101+
/// {@endtemplate}
100102
final ShapeBorder? shape;
101103

102104
/// If specified, [style] defines the font used for [ListTile] titles.

packages/flutter/lib/src/material/switch_list_tile.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ class SwitchListTile extends StatelessWidget {
273273
this.selected = false,
274274
this.autofocus = false,
275275
this.controlAffinity = ListTileControlAffinity.platform,
276+
this.shape,
276277
}) : _switchListTileType = _SwitchListTileType.material,
277278
assert(value != null),
278279
assert(isThreeLine != null),
@@ -308,6 +309,7 @@ class SwitchListTile extends StatelessWidget {
308309
this.selected = false,
309310
this.autofocus = false,
310311
this.controlAffinity = ListTileControlAffinity.platform,
312+
this.shape,
311313
}) : _switchListTileType = _SwitchListTileType.adaptive,
312314
assert(value != null),
313315
assert(isThreeLine != null),
@@ -435,6 +437,9 @@ class SwitchListTile extends StatelessWidget {
435437
/// By default, the value of `controlAffinity` is [ListTileControlAffinity.platform].
436438
final ListTileControlAffinity controlAffinity;
437439

440+
/// {@macro flutter.material.ListTile.shape}
441+
final ShapeBorder? shape;
442+
438443
@override
439444
Widget build(BuildContext context) {
440445
Widget control;
@@ -497,6 +502,7 @@ class SwitchListTile extends StatelessWidget {
497502
onTap: onChanged != null ? () { onChanged!(!value); } : null,
498503
selected: selected,
499504
autofocus: autofocus,
505+
shape: shape,
500506
),
501507
),
502508
);

packages/flutter/test/material/checkbox_list_tile_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,21 @@ void main() {
224224
await tester.pumpAndSettle();
225225
expect(_value, false);
226226
});
227+
228+
testWidgets('CheckboxListTile respects shape', (WidgetTester tester) async {
229+
const ShapeBorder shapeBorder = RoundedRectangleBorder(
230+
borderRadius: BorderRadius.horizontal(right: Radius.circular(100))
231+
);
232+
233+
await tester.pumpWidget(wrap(
234+
child: const CheckboxListTile(
235+
value: false,
236+
onChanged: null,
237+
title: Text('Title'),
238+
shape: shapeBorder,
239+
),
240+
));
241+
242+
expect(tester.widget<InkWell>(find.byType(InkWell)).customBorder, shapeBorder);
243+
});
227244
}

packages/flutter/test/material/switch_list_tile_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,23 @@ void main() {
340340
expect(listTile.leading.runtimeType, Icon);
341341
expect(listTile.trailing.runtimeType, Switch);
342342
});
343+
344+
testWidgets('SwitchListTile respects shape', (WidgetTester tester) async {
345+
const ShapeBorder shapeBorder = RoundedRectangleBorder(
346+
borderRadius: BorderRadius.horizontal(right: Radius.circular(100))
347+
);
348+
349+
await tester.pumpWidget(const MaterialApp(
350+
home: Material(
351+
child: SwitchListTile(
352+
value: true,
353+
onChanged: null,
354+
title: Text('Title'),
355+
shape: shapeBorder,
356+
),
357+
),
358+
));
359+
360+
expect(tester.widget<InkWell>(find.byType(InkWell)).customBorder, shapeBorder);
361+
});
343362
}

0 commit comments

Comments
 (0)