diff --git a/packages/flutter/lib/src/material/radio_list_tile.dart b/packages/flutter/lib/src/material/radio_list_tile.dart index b67b2897c6..2e8a1c42a6 100644 --- a/packages/flutter/lib/src/material/radio_list_tile.dart +++ b/packages/flutter/lib/src/material/radio_list_tile.dart @@ -319,6 +319,7 @@ class RadioListTile 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 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 extends StatelessWidget { } : null, selected: selected, autofocus: autofocus, + contentPadding: contentPadding, ), ), ); diff --git a/packages/flutter/test/material/radio_list_tile_test.dart b/packages/flutter/test/material/radio_list_tile_test.dart index 88d693fef2..8f0742bc07 100644 --- a/packages/flutter/test/material/radio_list_tile_test.dart +++ b/packages/flutter/test/material/radio_list_tile_test.dart @@ -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( + groupValue: true, + value: true, + onChanged: null, + ).runtimeType; + + await tester.pumpWidget( + wrap( + child: Center( + child: RadioListTile( + 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 + }); }