Adds CheckboxListTile.checkboxShape (#95714)

This commit is contained in:
Viren Khatri 2022-01-24 22:28:01 +05:30 committed by GitHub
parent fd6547e121
commit 0978b96ecd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 6 deletions

View file

@ -137,6 +137,7 @@ class CheckboxListTile extends StatelessWidget {
this.contentPadding,
this.tristate = false,
this.shape,
this.checkboxShape,
this.selectedTileColor,
this.side,
this.visualDensity,
@ -256,6 +257,13 @@ class CheckboxListTile extends StatelessWidget {
/// {@macro flutter.material.ListTile.shape}
final ShapeBorder? shape;
/// {@macro flutter.material.checkbox.shape}
///
/// If this property is null then [CheckboxThemeData.shape] of [ThemeData.checkboxTheme]
/// is used. If that's null then the shape will be a [RoundedRectangleBorder]
/// with a circular corner radius of 1.0.
final OutlinedBorder? checkboxShape;
/// If non-null, defines the background color when [CheckboxListTile.selected] is true.
final Color? selectedTileColor;
@ -308,6 +316,7 @@ class CheckboxListTile extends StatelessWidget {
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
autofocus: autofocus,
tristate: tristate,
shape: checkboxShape,
side: side,
);
Widget? leading, trailing;

View file

@ -321,8 +321,8 @@ void main() {
expect(textColor('title'), activeColor);
});
testWidgets('CheckboxListTile respects checkbox side', (WidgetTester tester) async {
Widget buildApp(BorderSide side) {
testWidgets('CheckboxListTile respects checkbox shape and side', (WidgetTester tester) async {
Widget buildApp(BorderSide side, OutlinedBorder shape) {
return MaterialApp(
home: Material(
child: Center(
@ -331,32 +331,47 @@ void main() {
value: false,
onChanged: (bool? newValue) {},
side: side,
checkboxShape: shape,
);
}),
),
),
);
}
const RoundedRectangleBorder border1 = RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(5)));
const BorderSide side1 = BorderSide(
color: Color(0xfff44336),
);
await tester.pumpWidget(buildApp(side1));
await tester.pumpWidget(buildApp(side1, border1));
expect(tester.widget<CheckboxListTile>(find.byType(CheckboxListTile)).side, side1);
expect(tester.widget<CheckboxListTile>(find.byType(CheckboxListTile)).checkboxShape, border1);
expect(tester.widget<Checkbox>(find.byType(Checkbox)).side, side1);
expect(tester.widget<Checkbox>(find.byType(Checkbox)).shape, border1);
expect(
Material.of(tester.element(find.byType(Checkbox))),
paints
..drrect(color: const Color(0xfff44336)),
..drrect(
color: const Color(0xfff44336),
outer: RRect.fromLTRBR(11.0, 11.0, 29.0, 29.0, const Radius.circular(5)),
inner: RRect.fromLTRBR(12.0, 12.0, 28.0, 28.0, const Radius.circular(4)),
),
);
const RoundedRectangleBorder border2 = RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(5)));
const BorderSide side2 = BorderSide(
width: 4.0,
color: Color(0xff424242),
);
await tester.pumpWidget(buildApp(side2));
await tester.pumpWidget(buildApp(side2, border2));
expect(tester.widget<Checkbox>(find.byType(Checkbox)).side, side2);
expect(tester.widget<Checkbox>(find.byType(Checkbox)).shape, border2);
expect(
Material.of(tester.element(find.byType(Checkbox))),
paints
..drrect(color: const Color(0xff424242)),
..drrect(
color: const Color(0xff424242),
outer: RRect.fromLTRBR(11.0, 11.0, 29.0, 29.0, const Radius.circular(5)),
inner: RRect.fromLTRBR(15.0, 15.0, 25.0, 25.0, const Radius.circular(1)),
),
);
});