Add Border customization to CheckboxListTile (reprise) (#93271)

This commit is contained in:
Hans Muller 2021-11-08 13:52:41 -08:00 committed by GitHub
parent aaf1003a77
commit 2b33dae9ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 2 deletions

View File

@ -301,8 +301,9 @@ class Checkbox extends StatefulWidget {
/// compatibility. /// compatibility.
/// {@endtemplate} /// {@endtemplate}
/// ///
/// If this property is null then [CheckboxThemeData.side] of [ThemeData.checkboxTheme] /// If this property is null, then [CheckboxThemeData.side] of
/// is used. If that's null then the side will be width 2. /// [ThemeData.checkboxTheme] is used. If that is also null, then the side
/// will be width 2.
final BorderSide? side; final BorderSide? side;
/// The width of a checkbox widget. /// The width of a checkbox widget.

View File

@ -138,6 +138,7 @@ class CheckboxListTile extends StatelessWidget {
this.tristate = false, this.tristate = false,
this.shape, this.shape,
this.selectedTileColor, this.selectedTileColor,
this.side,
this.visualDensity, this.visualDensity,
this.focusNode, this.focusNode,
this.enableFeedback, this.enableFeedback,
@ -258,6 +259,15 @@ class CheckboxListTile extends StatelessWidget {
/// If non-null, defines the background color when [CheckboxListTile.selected] is true. /// If non-null, defines the background color when [CheckboxListTile.selected] is true.
final Color? selectedTileColor; final Color? selectedTileColor;
/// {@macro flutter.material.checkbox.side}
///
/// The given value is passed directly to [Checkbox.side].
///
/// If this property is null, then [CheckboxThemeData.side] of
/// [ThemeData.checkboxTheme] is used. If that is also null, then the side
/// will be width 2.
final BorderSide? side;
/// Defines how compact the list tile's layout will be. /// Defines how compact the list tile's layout will be.
/// ///
/// {@macro flutter.material.themedata.visualDensity} /// {@macro flutter.material.themedata.visualDensity}
@ -298,6 +308,7 @@ class CheckboxListTile extends StatelessWidget {
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
autofocus: autofocus, autofocus: autofocus,
tristate: tristate, tristate: tristate,
side: side,
); );
Widget? leading, trailing; Widget? leading, trailing;
switch (controlAffinity) { switch (controlAffinity) {

View File

@ -321,6 +321,45 @@ void main() {
expect(textColor('title'), activeColor); expect(textColor('title'), activeColor);
}); });
testWidgets('CheckboxListTile respects checkbox side', (WidgetTester tester) async {
Widget buildApp(BorderSide side) {
return MaterialApp(
home: Material(
child: Center(
child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
return CheckboxListTile(
value: false,
onChanged: (bool? newValue) {},
side: side,
);
}),
),
),
);
}
const BorderSide side1 = BorderSide(
color: Color(0xfff44336),
);
await tester.pumpWidget(buildApp(side1));
expect(tester.widget<CheckboxListTile>(find.byType(CheckboxListTile)).side, side1);
expect(tester.widget<Checkbox>(find.byType(Checkbox)).side, side1);
expect(
Material.of(tester.element(find.byType(Checkbox))),
paints
..drrect(color: const Color(0xfff44336)),
);
const BorderSide side2 = BorderSide(
color: Color(0xff424242),
);
await tester.pumpWidget(buildApp(side2));
expect(tester.widget<Checkbox>(find.byType(Checkbox)).side, side2);
expect(
Material.of(tester.element(find.byType(Checkbox))),
paints
..drrect(color: const Color(0xff424242)),
);
});
testWidgets('CheckboxListTile respects visualDensity', (WidgetTester tester) async { testWidgets('CheckboxListTile respects visualDensity', (WidgetTester tester) async {
const Key key = Key('test'); const Key key = Key('test');
Future<void> buildTest(VisualDensity visualDensity) async { Future<void> buildTest(VisualDensity visualDensity) async {