Add contentPadding property for RadioListTile (#67438)
Exposes contentPadding property for RadioListTile from its appropriate ListTile.
This commit is contained in:
parent
053ebf2c08
commit
7f1540f323
@ -319,6 +319,7 @@ class RadioListTile<T> extends StatelessWidget {
|
||||
this.selected = false,
|
||||
this.controlAffinity = ListTileControlAffinity.platform,
|
||||
this.autofocus = false,
|
||||
this.contentPadding,
|
||||
|
||||
}) : assert(toggleable != null),
|
||||
assert(isThreeLine != null),
|
||||
@ -469,6 +470,14 @@ class RadioListTile<T> extends StatelessWidget {
|
||||
/// {@macro flutter.widgets.Focus.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.
|
||||
///
|
||||
/// To control this value, set [value] and [groupValue] appropriately.
|
||||
@ -519,6 +528,7 @@ class RadioListTile<T> extends StatelessWidget {
|
||||
} : null,
|
||||
selected: selected,
|
||||
autofocus: autofocus,
|
||||
contentPadding: contentPadding,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -606,4 +606,44 @@ void main() {
|
||||
await tester.pump();
|
||||
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
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user