Add innerRadius to RadioThemeData (#173120)

Part of https://github.com/flutter/flutter/issues/168787

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
Valentin Vignal 2025-08-03 00:20:06 +08:00 committed by GitHub
parent cc4f1a09f1
commit e5fd5b6be5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 58 additions and 17 deletions

View File

@ -426,9 +426,11 @@ class Radio<T> extends StatefulWidget {
/// * [WidgetState.hovered].
/// * [WidgetState.focused].
/// * [WidgetState.disabled].
///
/// If null, then it is transparent in all states.
/// {@endtemplate}
///
/// If null, then [RadioThemeData.backgroundColor] of [ThemeData.radioTheme]
/// is used. If that is also null the default value is transparent in all
/// states.
final WidgetStateProperty<Color?>? backgroundColor;
/// {@template flutter.material.Radio.side}
@ -443,20 +445,23 @@ class Radio<T> extends StatefulWidget {
/// * [WidgetState.hovered].
/// * [WidgetState.focused].
/// * [WidgetState.disabled].
/// {@endtemplate}
///
/// If null, then [RadioThemeData.side] of [ThemeData.radioTheme] is used. If
/// that is also null, the default value is a border using the fill color.
/// {@endtemplate}
final BorderSide? side;
/// {@template flutter.material.Radio.innerRadius}
/// The radius of the inner circle of the radio button, in all [WidgetState]s.
///
/// Resolves in the following states:
/// * [WidgetState.hovered].
/// * [WidgetState.focused].
/// * [WidgetState.disabled].
/// {@endtemplate}
///
/// If null, then it defaults to `4.5` in all states.
/// If null, then [RadioThemeData.innerRadius] of [ThemeData.radioTheme] is
/// used. If that is also null, the default value is `4.5` in all states.
final WidgetStateProperty<double?>? innerRadius;
@override
@ -761,7 +766,10 @@ class _RadioPaintState extends State<_RadioPaint> {
strokeAlign: BorderSide.strokeAlignCenter,
);
final double innerRadius = widget.innerRadius?.resolve(activeStates) ?? _kInnerRadius;
final double innerRadius =
widget.innerRadius?.resolve(activeStates) ??
radioTheme.innerRadius?.resolve(activeStates) ??
_kInnerRadius;
return CustomPaint(
size: size,

View File

@ -51,6 +51,7 @@ class RadioThemeData with Diagnosticable {
this.visualDensity,
this.backgroundColor,
this.side,
this.innerRadius,
});
/// {@macro flutter.widget.RawRadio.mouseCursor}
@ -89,11 +90,23 @@ class RadioThemeData with Diagnosticable {
final VisualDensity? visualDensity;
/// {@macro flutter.material.Radio.backgroundColor}
///
/// If specified, overrides the default value of [Radio.backgroundColor]. The
/// default value is transparent in all states.
final WidgetStateProperty<Color?>? backgroundColor;
/// {@macro flutter.material.Radio.side}
///
/// If specified, overrides the default value of [Radio.side]. The default
/// value is a border using the fill color.
final BorderSide? side;
/// {@macro flutter.material.Radio.innerRadius}
///
/// If specified, overrides the default value of [Radio.innerRadius]. The
/// default value is `4.5` in all states.
final WidgetStateProperty<double?>? innerRadius;
/// Creates a copy of this object but with the given fields replaced with the
/// new values.
RadioThemeData copyWith({
@ -105,6 +118,7 @@ class RadioThemeData with Diagnosticable {
VisualDensity? visualDensity,
WidgetStateProperty<Color?>? backgroundColor,
BorderSide? side,
WidgetStateProperty<double?>? innerRadius,
}) {
return RadioThemeData(
mouseCursor: mouseCursor ?? this.mouseCursor,
@ -115,6 +129,7 @@ class RadioThemeData with Diagnosticable {
visualDensity: visualDensity ?? this.visualDensity,
backgroundColor: backgroundColor ?? this.backgroundColor,
side: side ?? this.side,
innerRadius: innerRadius ?? this.innerRadius,
);
}
@ -144,9 +159,9 @@ class RadioThemeData with Diagnosticable {
}
return RadioThemeData(
mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor,
fillColor: MaterialStateProperty.lerp<Color?>(a?.fillColor, b?.fillColor, t, Color.lerp),
fillColor: WidgetStateProperty.lerp<Color?>(a?.fillColor, b?.fillColor, t, Color.lerp),
materialTapTargetSize: t < 0.5 ? a?.materialTapTargetSize : b?.materialTapTargetSize,
overlayColor: MaterialStateProperty.lerp<Color?>(
overlayColor: WidgetStateProperty.lerp<Color?>(
a?.overlayColor,
b?.overlayColor,
t,
@ -161,6 +176,7 @@ class RadioThemeData with Diagnosticable {
Color.lerp,
),
side: _lerpSides(a?.side, b?.side, t),
innerRadius: WidgetStateProperty.lerp<double?>(a?.innerRadius, b?.innerRadius, t, lerpDouble),
);
}
@ -174,6 +190,7 @@ class RadioThemeData with Diagnosticable {
visualDensity,
backgroundColor,
side,
innerRadius,
);
@override
@ -192,28 +209,25 @@ class RadioThemeData with Diagnosticable {
other.materialTapTargetSize == materialTapTargetSize &&
other.visualDensity == visualDensity &&
other.backgroundColor == backgroundColor &&
other.side == side;
other.side == side &&
other.innerRadius == innerRadius;
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(
DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>(
DiagnosticsProperty<WidgetStateProperty<MouseCursor?>>(
'mouseCursor',
mouseCursor,
defaultValue: null,
),
);
properties.add(
DiagnosticsProperty<MaterialStateProperty<Color?>>(
'fillColor',
fillColor,
defaultValue: null,
),
DiagnosticsProperty<WidgetStateProperty<Color?>>('fillColor', fillColor, defaultValue: null),
);
properties.add(
DiagnosticsProperty<MaterialStateProperty<Color?>>(
DiagnosticsProperty<WidgetStateProperty<Color?>>(
'overlayColor',
overlayColor,
defaultValue: null,
@ -238,6 +252,13 @@ class RadioThemeData with Diagnosticable {
),
);
properties.add(DiagnosticsProperty<BorderSide>('side', side, defaultValue: null));
properties.add(
DiagnosticsProperty<WidgetStateProperty<double?>>(
'innerRadius',
innerRadius,
defaultValue: null,
),
);
}
}

View File

@ -29,6 +29,7 @@ void main() {
expect(themeData.visualDensity, null);
expect(themeData.backgroundColor, null);
expect(themeData.side, null);
expect(themeData.innerRadius, null);
const RadioTheme theme = RadioTheme(data: RadioThemeData(), child: SizedBox());
expect(theme.data.mouseCursor, null);
@ -39,6 +40,7 @@ void main() {
expect(theme.data.visualDensity, null);
expect(theme.data.backgroundColor, null);
expect(theme.data.side, null);
expect(theme.data.innerRadius, null);
});
testWidgets('Default RadioThemeData debugFillProperties', (WidgetTester tester) async {
@ -64,6 +66,7 @@ void main() {
visualDensity: VisualDensity.standard,
backgroundColor: WidgetStatePropertyAll<Color>(Color(0xfffffff2)),
side: BorderSide(color: Color(0xfffffff3), width: 2),
innerRadius: WidgetStatePropertyAll<double>(5.0),
).debugFillProperties(builder);
final List<String> description = builder.properties
@ -82,6 +85,7 @@ void main() {
'visualDensity: VisualDensity#00000(h: 0.0, v: 0.0)',
'backgroundColor: WidgetStatePropertyAll(${const Color(0xfffffff2)})',
'side: BorderSide(color: ${const Color(0xfffffff3)}, width: 2.0)',
'innerRadius: WidgetStatePropertyAll(5.0)',
]),
);
});
@ -99,6 +103,7 @@ void main() {
const double splashRadius = 1.0;
const MaterialTapTargetSize materialTapTargetSize = MaterialTapTargetSize.shrinkWrap;
const VisualDensity visualDensity = VisualDensity(horizontal: 1, vertical: 1);
const double innerRadius = 5.0;
Widget buildRadio({bool selected = false, bool autofocus = false}) {
return MaterialApp(
@ -129,6 +134,7 @@ void main() {
}
return defaultBackgroundColor;
}),
innerRadius: const WidgetStatePropertyAll<double>(innerRadius),
),
),
home: Scaffold(
@ -161,7 +167,8 @@ void main() {
_getRadioMaterial(tester),
paints
..circle(color: selectedBackgroundColor)
..circle(color: selectedFillColor),
..circle(color: selectedFillColor)
..circle(color: selectedFillColor, radius: innerRadius),
);
// Radio with hover.
@ -243,6 +250,7 @@ void main() {
const double themeSplashRadius = 1.0;
const MaterialTapTargetSize themeMaterialTapTargetSize = MaterialTapTargetSize.padded;
const VisualDensity themeVisualDensity = VisualDensity.standard;
const double themeInnerRadius = 5.0;
const MouseCursor mouseCursor = SystemMouseCursors.text;
const Color defaultFillColor = Color(0xeffffff0);
@ -254,6 +262,7 @@ void main() {
const double splashRadius = 2.0;
const MaterialTapTargetSize materialTapTargetSize = MaterialTapTargetSize.shrinkWrap;
const VisualDensity visualDensity = VisualDensity(horizontal: 1, vertical: 1);
const double innerRadius = 6.0;
Widget buildRadio({bool selected = false, bool autofocus = false}) {
return MaterialApp(
@ -284,6 +293,7 @@ void main() {
}
return themeDefaultBackgroundColor;
}),
innerRadius: const WidgetStatePropertyAll<double>(themeInnerRadius),
),
),
home: Scaffold(
@ -310,6 +320,7 @@ void main() {
}
return defaultBackgroundColor;
}),
innerRadius: const WidgetStatePropertyAll<double>(innerRadius),
),
),
);
@ -334,7 +345,8 @@ void main() {
_getRadioMaterial(tester),
paints
..circle(color: selectedBackgroundColor)
..circle(color: selectedFillColor),
..circle(color: selectedFillColor)
..circle(color: selectedFillColor, radius: innerRadius),
);
// Radio with hover.