From a2c2d2c8dea5b27897e3bc2db091cdeebfd737e1 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira <62367544+tilucasoli@users.noreply.github.com> Date: Fri, 16 May 2025 11:31:20 -0300 Subject: [PATCH] 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. --- .../flutter/lib/src/material/bottom_navigation_bar.dart | 2 +- packages/flutter/lib/src/material/elevated_button.dart | 6 +++--- packages/flutter/lib/src/material/filled_button.dart | 9 ++++----- packages/flutter/lib/src/material/outlined_button.dart | 7 ++++--- packages/flutter/lib/src/material/text_button.dart | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart index 5857c792506..24b62927764 100644 --- a/packages/flutter/lib/src/material/bottom_navigation_bar.dart +++ b/packages/flutter/lib/src/material/bottom_navigation_bar.dart @@ -631,9 +631,9 @@ class _Tile extends StatelessWidget { heightFactor: 1, child: Row( mainAxisSize: MainAxisSize.min, + spacing: 8, children: [ 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. diff --git a/packages/flutter/lib/src/material/elevated_button.dart b/packages/flutter/lib/src/material/elevated_button.dart index 73b572c11c1..7b6ae535295 100644 --- a/packages/flutter/lib/src/material/elevated_button.dart +++ b/packages/flutter/lib/src/material/elevated_button.dart @@ -539,7 +539,6 @@ class _ElevatedButtonWithIconChild extends StatelessWidget { buttonStyle?.textStyle?.resolve(const {})?.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 - ? [icon, SizedBox(width: gap), Flexible(child: label)] - : [Flexible(child: label), SizedBox(width: gap), icon], + ? [icon, Flexible(child: label)] + : [Flexible(child: label), icon], ); } } diff --git a/packages/flutter/lib/src/material/filled_button.dart b/packages/flutter/lib/src/material/filled_button.dart index 6c776c551b6..5b1e06743c5 100644 --- a/packages/flutter/lib/src/material/filled_button.dart +++ b/packages/flutter/lib/src/material/filled_button.dart @@ -588,9 +588,7 @@ class _FilledButtonWithIconChild extends StatelessWidget { buttonStyle?.textStyle?.resolve(const {})?.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 - ? [icon, SizedBox(width: gap), Flexible(child: label)] - : [Flexible(child: label), SizedBox(width: gap), icon], + ? [icon, Flexible(child: label)] + : [Flexible(child: label), icon], ); } } diff --git a/packages/flutter/lib/src/material/outlined_button.dart b/packages/flutter/lib/src/material/outlined_button.dart index 82191c60b73..3a32c6915fe 100644 --- a/packages/flutter/lib/src/material/outlined_button.dart +++ b/packages/flutter/lib/src/material/outlined_button.dart @@ -487,7 +487,7 @@ class _OutlinedButtonWithIconChild extends StatelessWidget { buttonStyle?.textStyle?.resolve(const {})?.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 - ? [icon, SizedBox(width: gap), Flexible(child: label)] - : [Flexible(child: label), SizedBox(width: gap), icon], + ? [icon, Flexible(child: label)] + : [Flexible(child: label), icon], ); } } diff --git a/packages/flutter/lib/src/material/text_button.dart b/packages/flutter/lib/src/material/text_button.dart index d665ec7170d..59a549f1423 100644 --- a/packages/flutter/lib/src/material/text_button.dart +++ b/packages/flutter/lib/src/material/text_button.dart @@ -516,7 +516,6 @@ class _TextButtonWithIconChild extends StatelessWidget { buttonStyle?.textStyle?.resolve(const {})?.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 - ? [icon, SizedBox(width: gap), Flexible(child: label)] - : [Flexible(child: label), SizedBox(width: gap), icon], + ? [icon, Flexible(child: label)] + : [Flexible(child: label), icon], ); } }