RadioListTile: add property to scale the radio (#156292)

Added a property in the RadioListTile to scale the underlying Radio using `Transform.scale`.

Fixes: #81334
This commit is contained in:
Jatin Nagar
2024-10-12 21:20:36 +05:30
committed by GitHub
parent ba778dea6d
commit b3491acb0d
2 changed files with 57 additions and 1 deletions

View File

@@ -200,6 +200,7 @@ class RadioListTile<T> extends StatelessWidget {
this.focusNode,
this.onFocusChange,
this.enableFeedback,
this.radioScaleFactor = 1.0,
this.internalAddSemanticForOnTap = false,
}) : _radioType = _RadioType.material,
useCupertinoCheckmarkStyle = false,
@@ -240,6 +241,7 @@ class RadioListTile<T> extends StatelessWidget {
this.focusNode,
this.onFocusChange,
this.enableFeedback,
this.radioScaleFactor = 1.0,
this.useCupertinoCheckmarkStyle = false,
this.internalAddSemanticForOnTap = false,
}) : _radioType = _RadioType.adaptive,
@@ -468,9 +470,14 @@ class RadioListTile<T> extends StatelessWidget {
/// Defaults to false.
final bool useCupertinoCheckmarkStyle;
/// Controls the scaling factor applied to the [Radio] within the [RadioListTile].
///
/// Defaults to 1.0.
final double radioScaleFactor;
@override
Widget build(BuildContext context) {
final Widget control;
Widget control;
switch (_radioType) {
case _RadioType.material:
control = ExcludeFocus(
@@ -509,6 +516,13 @@ class RadioListTile<T> extends StatelessWidget {
);
}
if (radioScaleFactor != 1.0) {
control = Transform.scale(
scale: radioScaleFactor,
child: control,
);
}
final ListTileThemeData listTileTheme = ListTileTheme.of(context);
final ListTileControlAffinity effectiveControlAffinity =
controlAffinity ?? listTileTheme.controlAffinity ?? ListTileControlAffinity.platform;

View File

@@ -1588,4 +1588,46 @@ void main() {
final Offset offsetPlatform = tester.getTopLeft(platform);
expect(offsetPlatform, const Offset(72.0, 16.0));
});
testWidgets('RadioListTile renders with default scale', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(
home: Material(
child: RadioListTile<bool>(
value: false,
groupValue: false,
onChanged: null,
),
),
));
final Finder transformFinder = find.ancestor(
of: find.byType(Radio<bool>),
matching: find.byType(Transform),
);
expect(transformFinder, findsNothing);
});
testWidgets('RadioListTile respects radioScaleFactor', (WidgetTester tester) async {
const double scale = 1.4;
await tester.pumpWidget(const MaterialApp(
home: Material(
child: RadioListTile<bool>(
value: false,
groupValue: false,
onChanged: null,
radioScaleFactor: scale,
),
),
));
final Transform widget = tester.widget(
find.ancestor(
of: find.byType(Radio<bool>),
matching: find.byType(Transform),
),
);
expect(widget.transform.getMaxScaleOnAxis(), scale);
});
}