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,