diff --git a/packages/flutter/lib/src/material/checkbox_list_tile.dart b/packages/flutter/lib/src/material/checkbox_list_tile.dart index 990b63c7ac..fd8915062e 100644 --- a/packages/flutter/lib/src/material/checkbox_list_tile.dart +++ b/packages/flutter/lib/src/material/checkbox_list_tile.dart @@ -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; diff --git a/packages/flutter/test/material/checkbox_list_tile_test.dart b/packages/flutter/test/material/checkbox_list_tile_test.dart index 4f7ea9e730..b4a1ca29dd 100644 --- a/packages/flutter/test/material/checkbox_list_tile_test.dart +++ b/packages/flutter/test/material/checkbox_list_tile_test.dart @@ -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(find.byType(CheckboxListTile)).side, side1); + expect(tester.widget(find.byType(CheckboxListTile)).checkboxShape, border1); expect(tester.widget(find.byType(Checkbox)).side, side1); + expect(tester.widget(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(find.byType(Checkbox)).side, side2); + expect(tester.widget(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)), + ), ); });