From 297e7477d98273b3280738fb48cd269dfddf0a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Sharma?= <737941+loic-sharma@users.noreply.github.com> Date: Wed, 17 Dec 2025 12:04:12 -0800 Subject: [PATCH] Update the Material `IconAlignment` sample (#179159) Migrates the samples to remove references to the deprecated `ButtonStyleButton.iconAlignment`. The sample doesn't actually use `ButtonStyleButton.iconAlignment` directly, but it does refer to it in docs. Addresses: https://github.com/flutter/flutter/issues/179149 ## 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. [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 --- .../dropdown_menu/dropdown_menu.0.dart | 10 +- .../icon_alignment.0.dart} | 24 ++-- ...on_style_button.icon_alignment.0_test.dart | 107 ------------------ .../icon_alignment/icon_alignment.0_test.dart | 104 +++++++++++++++++ .../lib/src/material/button_style_button.dart | 6 +- .../lib/src/material/elevated_button.dart | 2 +- .../lib/src/material/filled_button.dart | 2 +- .../lib/src/material/outlined_button.dart | 2 +- .../flutter/lib/src/material/text_button.dart | 2 +- 9 files changed, 126 insertions(+), 133 deletions(-) rename examples/api/lib/material/{button_style_button/button_style_button.icon_alignment.0.dart => icon_alignment/icon_alignment.0.dart} (86%) delete mode 100644 examples/api/test/material/button_style_button/button_style_button.icon_alignment.0_test.dart create mode 100644 examples/api/test/material/icon_alignment/icon_alignment.0_test.dart diff --git a/examples/api/lib/material/dropdown_menu/dropdown_menu.0.dart b/examples/api/lib/material/dropdown_menu/dropdown_menu.0.dart index efc04be7ce2..f3b8a87ae22 100644 --- a/examples/api/lib/material/dropdown_menu/dropdown_menu.0.dart +++ b/examples/api/lib/material/dropdown_menu/dropdown_menu.0.dart @@ -5,11 +5,11 @@ import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; -// Flutter code sample for [DropdownMenu]s. The first dropdown menu -// has the default outlined border and demos using the -// [DropdownMenuEntry] style parameter to customize its appearance. -// The second dropdown menu customizes the appearance of the dropdown -// menu's text field with its [DropdownMenu.inputDecorationTheme] parameter. +/// Flutter code sample for [DropdownMenu]s. The first dropdown menu +/// has the default outlined border and demos using the +/// [DropdownMenuEntry] style parameter to customize its appearance. +/// The second dropdown menu customizes the appearance of the dropdown +/// menu's text field with its [DropdownMenu.inputDecorationTheme] parameter. void main() { runApp(const DropdownMenuExample()); diff --git a/examples/api/lib/material/button_style_button/button_style_button.icon_alignment.0.dart b/examples/api/lib/material/icon_alignment/icon_alignment.0.dart similarity index 86% rename from examples/api/lib/material/button_style_button/button_style_button.icon_alignment.0.dart rename to examples/api/lib/material/icon_alignment/icon_alignment.0.dart index e343906dc03..c2c76ff37d3 100644 --- a/examples/api/lib/material/button_style_button/button_style_button.icon_alignment.0.dart +++ b/examples/api/lib/material/icon_alignment/icon_alignment.0.dart @@ -4,34 +4,30 @@ import 'package:flutter/material.dart'; -// ignore: deprecated_member_use -/// Flutter code sample for using [ButtonStyleButton.iconAlignment] parameter. +/// Flutter code sample for the [IconAlignment] property on various Material +/// button widgets. void main() { - runApp(const ButtonStyleButtonIconAlignmentApp()); + runApp(const IconAlignmentApp()); } -class ButtonStyleButtonIconAlignmentApp extends StatelessWidget { - const ButtonStyleButtonIconAlignmentApp({super.key}); +class IconAlignmentApp extends StatelessWidget { + const IconAlignmentApp({super.key}); @override Widget build(BuildContext context) { - return const MaterialApp( - home: Scaffold(body: ButtonStyleButtonIconAlignmentExample()), - ); + return const MaterialApp(home: Scaffold(body: IconAlignmentExample())); } } -class ButtonStyleButtonIconAlignmentExample extends StatefulWidget { - const ButtonStyleButtonIconAlignmentExample({super.key}); +class IconAlignmentExample extends StatefulWidget { + const IconAlignmentExample({super.key}); @override - State createState() => - _ButtonStyleButtonIconAlignmentExampleState(); + State createState() => _IconAlignmentExampleState(); } -class _ButtonStyleButtonIconAlignmentExampleState - extends State { +class _IconAlignmentExampleState extends State { TextDirection _textDirection = TextDirection.ltr; IconAlignment _iconAlignment = IconAlignment.start; diff --git a/examples/api/test/material/button_style_button/button_style_button.icon_alignment.0_test.dart b/examples/api/test/material/button_style_button/button_style_button.icon_alignment.0_test.dart deleted file mode 100644 index a3d5ec6aa9b..00000000000 --- a/examples/api/test/material/button_style_button/button_style_button.icon_alignment.0_test.dart +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/material.dart'; -import 'package:flutter_api_samples/material/button_style_button/button_style_button.icon_alignment.0.dart' - as example; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - testWidgets( - 'ButtonStyleButton.iconAlignment updates button icons alignment', - (WidgetTester tester) async { - await tester.pumpWidget( - const example.ButtonStyleButtonIconAlignmentApp(), - ); - - Finder findButtonMaterial(String text) { - return find - .ancestor(of: find.text(text), matching: find.byType(Material)) - .first; - } - - void expectedLeftIconPosition({ - required double iconOffset, - required double textButtonIconOffset, - }) { - expect( - tester.getTopLeft(findButtonMaterial('ElevatedButton')).dx, - tester.getTopLeft(find.byIcon(Icons.sunny)).dx - iconOffset, - ); - expect( - tester.getTopLeft(findButtonMaterial('FilledButton')).dx, - tester.getTopLeft(find.byIcon(Icons.beach_access)).dx - iconOffset, - ); - expect( - tester.getTopLeft(findButtonMaterial('FilledButton Tonal')).dx, - tester.getTopLeft(find.byIcon(Icons.cloud)).dx - iconOffset, - ); - expect( - tester.getTopLeft(findButtonMaterial('OutlinedButton')).dx, - tester.getTopLeft(find.byIcon(Icons.light)).dx - iconOffset, - ); - expect( - tester.getTopLeft(findButtonMaterial('TextButton')).dx, - tester.getTopLeft(find.byIcon(Icons.flight_takeoff)).dx - - textButtonIconOffset, - ); - } - - void expectedRightIconPosition({ - required double iconOffset, - required double textButtonIconOffset, - }) { - expect( - tester.getTopRight(findButtonMaterial('ElevatedButton')).dx, - tester.getTopRight(find.byIcon(Icons.sunny)).dx + iconOffset, - ); - expect( - tester.getTopRight(findButtonMaterial('FilledButton')).dx, - tester.getTopRight(find.byIcon(Icons.beach_access)).dx + iconOffset, - ); - expect( - tester.getTopRight(findButtonMaterial('FilledButton Tonal')).dx, - tester.getTopRight(find.byIcon(Icons.cloud)).dx + iconOffset, - ); - expect( - tester.getTopRight(findButtonMaterial('OutlinedButton')).dx, - tester.getTopRight(find.byIcon(Icons.light)).dx + iconOffset, - ); - expect( - tester.getTopRight(findButtonMaterial('TextButton')).dx, - tester.getTopRight(find.byIcon(Icons.flight_takeoff)).dx + - textButtonIconOffset, - ); - } - - // Test initial icon alignment in LTR. - expectedLeftIconPosition(iconOffset: 16, textButtonIconOffset: 12); - - // Update icon alignment to end. - await tester.tap(find.text('end')); - await tester.pumpAndSettle(); - - // Test icon alignment end in LTR. - expectedRightIconPosition(iconOffset: 24, textButtonIconOffset: 16); - - // Reset icon alignment to start. - await tester.tap(find.text('start')); - await tester.pumpAndSettle(); - - // Change text direction to RTL. - await tester.tap(find.text('RTL')); - await tester.pumpAndSettle(); - - // Test icon alignment start in LTR. - expectedRightIconPosition(iconOffset: 16, textButtonIconOffset: 12); - - // Update icon alignment to end. - await tester.tap(find.text('end')); - await tester.pumpAndSettle(); - - // Test icon alignment end in LTR. - expectedLeftIconPosition(iconOffset: 24, textButtonIconOffset: 16); - }, - ); -} diff --git a/examples/api/test/material/icon_alignment/icon_alignment.0_test.dart b/examples/api/test/material/icon_alignment/icon_alignment.0_test.dart new file mode 100644 index 00000000000..85cb5b88827 --- /dev/null +++ b/examples/api/test/material/icon_alignment/icon_alignment.0_test.dart @@ -0,0 +1,104 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_api_samples/material/icon_alignment/icon_alignment.0.dart' + as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets("IconAlignment updates buttons' icons alignment", ( + WidgetTester tester, + ) async { + await tester.pumpWidget(const example.IconAlignmentApp()); + + Finder findButtonMaterial(String text) { + return find + .ancestor(of: find.text(text), matching: find.byType(Material)) + .first; + } + + void expectedLeftIconPosition({ + required double iconOffset, + required double textButtonIconOffset, + }) { + expect( + tester.getTopLeft(findButtonMaterial('ElevatedButton')).dx, + tester.getTopLeft(find.byIcon(Icons.sunny)).dx - iconOffset, + ); + expect( + tester.getTopLeft(findButtonMaterial('FilledButton')).dx, + tester.getTopLeft(find.byIcon(Icons.beach_access)).dx - iconOffset, + ); + expect( + tester.getTopLeft(findButtonMaterial('FilledButton Tonal')).dx, + tester.getTopLeft(find.byIcon(Icons.cloud)).dx - iconOffset, + ); + expect( + tester.getTopLeft(findButtonMaterial('OutlinedButton')).dx, + tester.getTopLeft(find.byIcon(Icons.light)).dx - iconOffset, + ); + expect( + tester.getTopLeft(findButtonMaterial('TextButton')).dx, + tester.getTopLeft(find.byIcon(Icons.flight_takeoff)).dx - + textButtonIconOffset, + ); + } + + void expectedRightIconPosition({ + required double iconOffset, + required double textButtonIconOffset, + }) { + expect( + tester.getTopRight(findButtonMaterial('ElevatedButton')).dx, + tester.getTopRight(find.byIcon(Icons.sunny)).dx + iconOffset, + ); + expect( + tester.getTopRight(findButtonMaterial('FilledButton')).dx, + tester.getTopRight(find.byIcon(Icons.beach_access)).dx + iconOffset, + ); + expect( + tester.getTopRight(findButtonMaterial('FilledButton Tonal')).dx, + tester.getTopRight(find.byIcon(Icons.cloud)).dx + iconOffset, + ); + expect( + tester.getTopRight(findButtonMaterial('OutlinedButton')).dx, + tester.getTopRight(find.byIcon(Icons.light)).dx + iconOffset, + ); + expect( + tester.getTopRight(findButtonMaterial('TextButton')).dx, + tester.getTopRight(find.byIcon(Icons.flight_takeoff)).dx + + textButtonIconOffset, + ); + } + + // Test initial icon alignment in LTR. + expectedLeftIconPosition(iconOffset: 16, textButtonIconOffset: 12); + + // Update icon alignment to end. + await tester.tap(find.text('end')); + await tester.pumpAndSettle(); + + // Test icon alignment end in LTR. + expectedRightIconPosition(iconOffset: 24, textButtonIconOffset: 16); + + // Reset icon alignment to start. + await tester.tap(find.text('start')); + await tester.pumpAndSettle(); + + // Change text direction to RTL. + await tester.tap(find.text('RTL')); + await tester.pumpAndSettle(); + + // Test icon alignment start in LTR. + expectedRightIconPosition(iconOffset: 16, textButtonIconOffset: 12); + + // Update icon alignment to end. + await tester.tap(find.text('end')); + await tester.pumpAndSettle(); + + // Test icon alignment end in LTR. + expectedLeftIconPosition(iconOffset: 24, textButtonIconOffset: 16); + }); +} diff --git a/packages/flutter/lib/src/material/button_style_button.dart b/packages/flutter/lib/src/material/button_style_button.dart index a5a3d39f6c2..71be80bcc85 100644 --- a/packages/flutter/lib/src/material/button_style_button.dart +++ b/packages/flutter/lib/src/material/button_style_button.dart @@ -29,7 +29,7 @@ import 'theme.dart'; import 'theme_data.dart'; import 'tooltip.dart'; -/// {@template flutter.material.ButtonStyleButton.iconAlignment} +/// {@template flutter.material.ButtonStyle.iconAlignment} /// Determines the alignment of the icon within the widgets such as: /// - [ElevatedButton.icon], /// - [FilledButton.icon], @@ -48,7 +48,7 @@ import 'tooltip.dart'; /// This sample demonstrates how to use `iconAlignment` to align the button icon to the start /// or the end of the button. /// -/// ** See code in examples/api/lib/material/button_style_button/button_style_button.icon_alignment.0.dart ** +/// ** See code in examples/api/lib/material/icon_alignment/icon_alignment.0.dart ** /// {@end-tool} /// /// {@endtemplate} @@ -163,7 +163,7 @@ abstract class ButtonStyleButton extends StatefulWidget { /// Defaults to true. final bool? isSemanticButton; - /// {@macro flutter.material.ButtonStyleButton.iconAlignment} + /// {@macro flutter.material.ButtonStyle.iconAlignment} @Deprecated( 'Remove this parameter as it is now ignored. ' 'Use ButtonStyle.iconAlignment instead. ' diff --git a/packages/flutter/lib/src/material/elevated_button.dart b/packages/flutter/lib/src/material/elevated_button.dart index b1685182dce..2c1cde331eb 100644 --- a/packages/flutter/lib/src/material/elevated_button.dart +++ b/packages/flutter/lib/src/material/elevated_button.dart @@ -91,7 +91,7 @@ class ElevatedButton extends ButtonStyleButton { /// If [icon] is null, this constructor will create an [ElevatedButton] /// that doesn't display an icon. /// - /// {@macro flutter.material.ButtonStyleButton.iconAlignment} + /// {@macro flutter.material.ButtonStyle.iconAlignment} /// ElevatedButton.icon({ super.key, diff --git a/packages/flutter/lib/src/material/filled_button.dart b/packages/flutter/lib/src/material/filled_button.dart index ff52cd2157b..5d44226b4b1 100644 --- a/packages/flutter/lib/src/material/filled_button.dart +++ b/packages/flutter/lib/src/material/filled_button.dart @@ -101,7 +101,7 @@ class FilledButton extends ButtonStyleButton { /// If [icon] is null, this constructor will create a [FilledButton] /// that doesn't display an icon. /// - /// {@macro flutter.material.ButtonStyleButton.iconAlignment} + /// {@macro flutter.material.ButtonStyle.iconAlignment} /// FilledButton.icon({ super.key, diff --git a/packages/flutter/lib/src/material/outlined_button.dart b/packages/flutter/lib/src/material/outlined_button.dart index 56ea9fc6e18..d476c63ddd9 100644 --- a/packages/flutter/lib/src/material/outlined_button.dart +++ b/packages/flutter/lib/src/material/outlined_button.dart @@ -95,7 +95,7 @@ class OutlinedButton extends ButtonStyleButton { /// If [icon] is null, this constructor will create an outlined button /// that doesn't display an icon. /// - /// {@macro flutter.material.ButtonStyleButton.iconAlignment} + /// {@macro flutter.material.ButtonStyle.iconAlignment} /// OutlinedButton.icon({ super.key, diff --git a/packages/flutter/lib/src/material/text_button.dart b/packages/flutter/lib/src/material/text_button.dart index c2400249e89..272ebe00c39 100644 --- a/packages/flutter/lib/src/material/text_button.dart +++ b/packages/flutter/lib/src/material/text_button.dart @@ -104,7 +104,7 @@ class TextButton extends ButtonStyleButton { /// If [icon] is null, this constructor will create a [TextButton] /// that doesn't display an icon. /// - /// {@macro flutter.material.ButtonStyleButton.iconAlignment} + /// {@macro flutter.material.ButtonStyle.iconAlignment} /// TextButton.icon({ super.key,