Add contentPadding property for RadioListTile (#67438)

Exposes contentPadding property for RadioListTile from its appropriate ListTile.
This commit is contained in:
Anurag Roy 2020-10-13 02:52:01 +05:30 committed by GitHub
parent 053ebf2c08
commit 7f1540f323
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 0 deletions

View File

@ -319,6 +319,7 @@ class RadioListTile<T> extends StatelessWidget {
this.selected = false, this.selected = false,
this.controlAffinity = ListTileControlAffinity.platform, this.controlAffinity = ListTileControlAffinity.platform,
this.autofocus = false, this.autofocus = false,
this.contentPadding,
}) : assert(toggleable != null), }) : assert(toggleable != null),
assert(isThreeLine != null), assert(isThreeLine != null),
@ -469,6 +470,14 @@ class RadioListTile<T> extends StatelessWidget {
/// {@macro flutter.widgets.Focus.autofocus} /// {@macro flutter.widgets.Focus.autofocus}
final bool autofocus; final bool autofocus;
/// Defines the insets surrounding the contents of the tile.
///
/// Insets the [Radio], [title], [subtitle], and [secondary] widgets
/// in [RadioListTile].
///
/// When null, `EdgeInsets.symmetric(horizontal: 16.0)` is used.
final EdgeInsetsGeometry? contentPadding;
/// Whether this radio button is checked. /// Whether this radio button is checked.
/// ///
/// To control this value, set [value] and [groupValue] appropriately. /// To control this value, set [value] and [groupValue] appropriately.
@ -519,6 +528,7 @@ class RadioListTile<T> extends StatelessWidget {
} : null, } : null,
selected: selected, selected: selected,
autofocus: autofocus, autofocus: autofocus,
contentPadding: contentPadding,
), ),
), ),
); );

View File

@ -606,4 +606,44 @@ void main() {
await tester.pump(); await tester.pump();
expect(Focus.of(childKey.currentContext!)!.hasPrimaryFocus, isFalse); expect(Focus.of(childKey.currentContext!)!.hasPrimaryFocus, isFalse);
}); });
testWidgets('RadioListTile contentPadding test', (WidgetTester tester) async {
final Type radioType = const Radio<bool>(
groupValue: true,
value: true,
onChanged: null,
).runtimeType;
await tester.pumpWidget(
wrap(
child: Center(
child: RadioListTile<bool>(
groupValue: true,
value: true,
title: const Text('Title'),
onChanged: (_){},
contentPadding: const EdgeInsets.fromLTRB(8, 10, 15, 20),
)
)
)
);
final Rect paddingRect = tester.getRect(find.byType(Padding));
final Rect radioRect = tester.getRect(find.byType(radioType));
final Rect titleRect = tester.getRect(find.text('Title'));
// Get the taller Rect of the Radio and Text widgets
final Rect tallerRect = radioRect.height > titleRect.height ? radioRect : titleRect;
// Get the extra height between the tallerRect and ListTile height
final double extraHeight = 56 - tallerRect.height;
// Check for correct top and bottom padding
expect(paddingRect.top, tallerRect.top - extraHeight / 2 - 10); //top padding
expect(paddingRect.bottom, tallerRect.bottom + extraHeight / 2 + 20); //bottom padding
// Check for correct left and right padding
expect(paddingRect.left, radioRect.left - 8); //left padding
expect(paddingRect.right, titleRect.right + 15); //right padding
});
} }