Replace SizedBox spacing with spacing parameter in Row usages (#168688)

This PR refactors Flutter widgets that use SizedBox for spacing between
children in Row into using the spacing parameter instead.

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
This commit is contained in:
Lucas Oliveira 2025-05-16 11:31:20 -03:00 committed by GitHub
parent c685293fc4
commit a2c2d2c8de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 15 additions and 15 deletions

View File

@ -631,9 +631,9 @@ class _Tile extends StatelessWidget {
heightFactor: 1,
child: Row(
mainAxisSize: MainAxisSize.min,
spacing: 8,
children: <Widget>[
icon,
const SizedBox(width: 8),
// Flexible lets the overflow property of
// label to work and IntrinsicWidth gives label a
// reasonable width preventing extra space before it.

View File

@ -539,7 +539,6 @@ class _ElevatedButtonWithIconChild extends StatelessWidget {
buttonStyle?.textStyle?.resolve(const <MaterialState>{})?.fontSize ?? 14.0;
final double scale =
clampDouble(MediaQuery.textScalerOf(context).scale(defaultFontSize) / 14.0, 1.0, 2.0) - 1.0;
final double gap = lerpDouble(8, 4, scale)!;
final ElevatedButtonThemeData elevatedButtonTheme = ElevatedButtonTheme.of(context);
final IconAlignment effectiveIconAlignment =
iconAlignment ??
@ -548,10 +547,11 @@ class _ElevatedButtonWithIconChild extends StatelessWidget {
IconAlignment.start;
return Row(
mainAxisSize: MainAxisSize.min,
spacing: lerpDouble(8, 4, scale)!,
children:
effectiveIconAlignment == IconAlignment.start
? <Widget>[icon, SizedBox(width: gap), Flexible(child: label)]
: <Widget>[Flexible(child: label), SizedBox(width: gap), icon],
? <Widget>[icon, Flexible(child: label)]
: <Widget>[Flexible(child: label), icon],
);
}
}

View File

@ -588,9 +588,7 @@ class _FilledButtonWithIconChild extends StatelessWidget {
buttonStyle?.textStyle?.resolve(const <MaterialState>{})?.fontSize ?? 14.0;
final double scale =
clampDouble(MediaQuery.textScalerOf(context).scale(defaultFontSize) / 14.0, 1.0, 2.0) - 1.0;
// Adjust the gap based on the text scale factor. Start at 8, and lerp
// to 4 based on how large the text is.
final double gap = lerpDouble(8, 4, scale)!;
final FilledButtonThemeData filledButtonTheme = FilledButtonTheme.of(context);
final IconAlignment effectiveIconAlignment =
iconAlignment ??
@ -599,10 +597,11 @@ class _FilledButtonWithIconChild extends StatelessWidget {
IconAlignment.start;
return Row(
mainAxisSize: MainAxisSize.min,
spacing: lerpDouble(8, 4, scale)!,
children:
effectiveIconAlignment == IconAlignment.start
? <Widget>[icon, SizedBox(width: gap), Flexible(child: label)]
: <Widget>[Flexible(child: label), SizedBox(width: gap), icon],
? <Widget>[icon, Flexible(child: label)]
: <Widget>[Flexible(child: label), icon],
);
}
}

View File

@ -487,7 +487,7 @@ class _OutlinedButtonWithIconChild extends StatelessWidget {
buttonStyle?.textStyle?.resolve(const <MaterialState>{})?.fontSize ?? 14.0;
final double scale =
clampDouble(MediaQuery.textScalerOf(context).scale(defaultFontSize) / 14.0, 1.0, 2.0) - 1.0;
final double gap = lerpDouble(8, 4, scale)!;
final OutlinedButtonThemeData outlinedButtonTheme = OutlinedButtonTheme.of(context);
final IconAlignment effectiveIconAlignment =
iconAlignment ??
@ -496,10 +496,11 @@ class _OutlinedButtonWithIconChild extends StatelessWidget {
IconAlignment.start;
return Row(
mainAxisSize: MainAxisSize.min,
spacing: lerpDouble(8, 4, scale)!,
children:
effectiveIconAlignment == IconAlignment.start
? <Widget>[icon, SizedBox(width: gap), Flexible(child: label)]
: <Widget>[Flexible(child: label), SizedBox(width: gap), icon],
? <Widget>[icon, Flexible(child: label)]
: <Widget>[Flexible(child: label), icon],
);
}
}

View File

@ -516,7 +516,6 @@ class _TextButtonWithIconChild extends StatelessWidget {
buttonStyle?.textStyle?.resolve(const <MaterialState>{})?.fontSize ?? 14.0;
final double scale =
clampDouble(MediaQuery.textScalerOf(context).scale(defaultFontSize) / 14.0, 1.0, 2.0) - 1.0;
final double gap = lerpDouble(8, 4, scale)!;
final TextButtonThemeData textButtonTheme = TextButtonTheme.of(context);
final IconAlignment effectiveIconAlignment =
iconAlignment ??
@ -525,10 +524,11 @@ class _TextButtonWithIconChild extends StatelessWidget {
IconAlignment.start;
return Row(
mainAxisSize: MainAxisSize.min,
spacing: lerpDouble(8, 4, scale)!,
children:
effectiveIconAlignment == IconAlignment.start
? <Widget>[icon, SizedBox(width: gap), Flexible(child: label)]
: <Widget>[Flexible(child: label), SizedBox(width: gap), icon],
? <Widget>[icon, Flexible(child: label)]
: <Widget>[Flexible(child: label), icon],
);
}
}