diff --git a/packages/flutter/lib/src/material/elevated_button.dart b/packages/flutter/lib/src/material/elevated_button.dart index 5e32c607bf..5ec8a889bc 100644 --- a/packages/flutter/lib/src/material/elevated_button.dart +++ b/packages/flutter/lib/src/material/elevated_button.dart @@ -95,6 +95,7 @@ class ElevatedButton extends ButtonStyleButton { FocusNode? focusNode, bool? autofocus, Clip? clipBehavior, + MaterialStatesController? statesController, required Widget icon, required Widget label, }) = _ElevatedButtonWithIcon; @@ -482,6 +483,7 @@ class _ElevatedButtonWithIcon extends ElevatedButton { super.focusNode, bool? autofocus, Clip? clipBehavior, + super.statesController, required Widget icon, required Widget label, }) : assert(icon != null), diff --git a/packages/flutter/lib/src/material/filled_button.dart b/packages/flutter/lib/src/material/filled_button.dart index 6e9341f228..08fdbb352d 100644 --- a/packages/flutter/lib/src/material/filled_button.dart +++ b/packages/flutter/lib/src/material/filled_button.dart @@ -96,6 +96,7 @@ class FilledButton extends ButtonStyleButton { FocusNode? focusNode, bool? autofocus, Clip? clipBehavior, + MaterialStatesController? statesController, required Widget icon, required Widget label, }) = _FilledButtonWithIcon; @@ -138,6 +139,7 @@ class FilledButton extends ButtonStyleButton { FocusNode? focusNode, bool? autofocus, Clip? clipBehavior, + MaterialStatesController? statesController, required Widget icon, required Widget label, }) { @@ -151,6 +153,7 @@ class FilledButton extends ButtonStyleButton { focusNode: focusNode, autofocus: autofocus, clipBehavior: clipBehavior, + statesController: statesController, icon: icon, label: label, ); @@ -430,6 +433,7 @@ class _FilledButtonWithIcon extends FilledButton { super.focusNode, bool? autofocus, Clip? clipBehavior, + super.statesController, required Widget icon, required Widget label, }) : assert(icon != null), @@ -450,6 +454,7 @@ class _FilledButtonWithIcon extends FilledButton { super.focusNode, bool? autofocus, Clip? clipBehavior, + super.statesController, required Widget icon, required Widget label, }) : assert(icon != null), diff --git a/packages/flutter/lib/src/material/outlined_button.dart b/packages/flutter/lib/src/material/outlined_button.dart index 1b8398feb5..7d3ecc622c 100644 --- a/packages/flutter/lib/src/material/outlined_button.dart +++ b/packages/flutter/lib/src/material/outlined_button.dart @@ -98,6 +98,7 @@ class OutlinedButton extends ButtonStyleButton { FocusNode? focusNode, bool? autofocus, Clip? clipBehavior, + MaterialStatesController? statesController, required Widget icon, required Widget label, }) = _OutlinedButtonWithIcon; @@ -413,6 +414,7 @@ class _OutlinedButtonWithIcon extends OutlinedButton { super.focusNode, bool? autofocus, Clip? clipBehavior, + super.statesController, required Widget icon, required Widget label, }) : assert(icon != null), diff --git a/packages/flutter/lib/src/material/text_button.dart b/packages/flutter/lib/src/material/text_button.dart index b3dc1b536c..9edbdc3839 100644 --- a/packages/flutter/lib/src/material/text_button.dart +++ b/packages/flutter/lib/src/material/text_button.dart @@ -107,6 +107,7 @@ class TextButton extends ButtonStyleButton { FocusNode? focusNode, bool? autofocus, Clip? clipBehavior, + MaterialStatesController? statesController, required Widget icon, required Widget label, }) = _TextButtonWithIcon; @@ -448,6 +449,7 @@ class _TextButtonWithIcon extends TextButton { super.focusNode, bool? autofocus, Clip? clipBehavior, + super.statesController, required Widget icon, required Widget label, }) : assert(icon != null), diff --git a/packages/flutter/test/material/elevated_button_test.dart b/packages/flutter/test/material/elevated_button_test.dart index 0648bf4eb2..3ce051537b 100644 --- a/packages/flutter/test/material/elevated_button_test.dart +++ b/packages/flutter/test/material/elevated_button_test.dart @@ -1624,7 +1624,7 @@ void main() { expect(material.textStyle!.color, Colors.white); }); - testWidgets('ElevatedButton statesController', (WidgetTester tester) async { + Future testStatesController(Widget? icon, WidgetTester tester) async { int count = 0; void valueChanged() { count += 1; @@ -1635,11 +1635,18 @@ void main() { await tester.pumpWidget( MaterialApp( home: Center( - child: ElevatedButton( - statesController: controller, - onPressed: () { }, - child: const Text('button'), - ), + child: icon == null + ? ElevatedButton( + statesController: controller, + onPressed: () { }, + child: const Text('button'), + ) + : ElevatedButton.icon( + statesController: controller, + onPressed: () { }, + icon: icon, + label: const Text('button'), + ), ), ), ); @@ -1647,7 +1654,7 @@ void main() { expect(controller.value, {}); expect(count, 0); - final Offset center = tester.getCenter(find.byType(ElevatedButton)); + final Offset center = tester.getCenter(find.byType(Text)); final TestGesture gesture = await tester.createGesture( kind: PointerDeviceKind.mouse, ); @@ -1698,11 +1705,18 @@ void main() { await tester.pumpWidget( MaterialApp( home: Center( - child: ElevatedButton( - statesController: controller, - onPressed: null, - child: const Text('button'), - ), + child: icon == null + ? ElevatedButton( + statesController: controller, + onPressed: null, + child: const Text('button'), + ) + : ElevatedButton.icon( + statesController: controller, + onPressed: null, + icon: icon, + label: const Text('button'), + ), ), ), ); @@ -1714,6 +1728,14 @@ void main() { expect(controller.value, {MaterialState.disabled}); expect(count, 11); await gesture.removePointer(); + } + + testWidgets('ElevatedButton statesController', (WidgetTester tester) async { + testStatesController(null, tester); + }); + + testWidgets('ElevatedButton.icon statesController', (WidgetTester tester) async { + testStatesController(const Icon(Icons.add), tester); }); testWidgets('Disabled ElevatedButton statesController', (WidgetTester tester) async { diff --git a/packages/flutter/test/material/filled_button_test.dart b/packages/flutter/test/material/filled_button_test.dart index f91e7a0562..fa659d30cf 100644 --- a/packages/flutter/test/material/filled_button_test.dart +++ b/packages/flutter/test/material/filled_button_test.dart @@ -1628,7 +1628,7 @@ void main() { expect(material.textStyle!.color, Colors.white); }); - testWidgets('FilledButton statesController', (WidgetTester tester) async { + Future testStatesController(Widget? icon, WidgetTester tester) async { int count = 0; void valueChanged() { count += 1; @@ -1639,11 +1639,18 @@ void main() { await tester.pumpWidget( MaterialApp( home: Center( - child: FilledButton( - statesController: controller, - onPressed: () { }, - child: const Text('button'), - ), + child: icon == null + ? FilledButton( + statesController: controller, + onPressed: () { }, + child: const Text('button'), + ) + : FilledButton.icon( + statesController: controller, + onPressed: () { }, + icon: icon, + label: const Text('button'), + ), ), ), ); @@ -1651,7 +1658,7 @@ void main() { expect(controller.value, {}); expect(count, 0); - final Offset center = tester.getCenter(find.byType(FilledButton)); + final Offset center = tester.getCenter(find.byType(Text)); final TestGesture gesture = await tester.createGesture( kind: PointerDeviceKind.mouse, ); @@ -1702,11 +1709,18 @@ void main() { await tester.pumpWidget( MaterialApp( home: Center( - child: FilledButton( - statesController: controller, - onPressed: null, - child: const Text('button'), - ), + child: icon == null + ? FilledButton( + statesController: controller, + onPressed: null, + child: const Text('button'), + ) + : FilledButton.icon( + statesController: controller, + onPressed: null, + icon: icon, + label: const Text('button'), + ), ), ), ); @@ -1718,6 +1732,14 @@ void main() { expect(controller.value, {MaterialState.disabled}); expect(count, 11); await gesture.removePointer(); + } + + testWidgets('FilledButton statesController', (WidgetTester tester) async { + testStatesController(null, tester); + }); + + testWidgets('FilledButton.icon statesController', (WidgetTester tester) async { + testStatesController(const Icon(Icons.add), tester); }); testWidgets('Disabled FilledButton statesController', (WidgetTester tester) async { diff --git a/packages/flutter/test/material/outlined_button_test.dart b/packages/flutter/test/material/outlined_button_test.dart index 5b2e3f9341..dcc53eebbf 100644 --- a/packages/flutter/test/material/outlined_button_test.dart +++ b/packages/flutter/test/material/outlined_button_test.dart @@ -1742,7 +1742,7 @@ void main() { expect(material.textStyle!.color, Colors.white); }); - testWidgets('OutlinedButton statesController', (WidgetTester tester) async { + Future testStatesController(Widget? icon, WidgetTester tester) async { int count = 0; void valueChanged() { count += 1; @@ -1753,11 +1753,18 @@ void main() { await tester.pumpWidget( MaterialApp( home: Center( - child: OutlinedButton( - statesController: controller, - onPressed: () { }, - child: const Text('button'), - ), + child: icon == null + ? OutlinedButton( + statesController: controller, + onPressed: () { }, + child: const Text('button'), + ) + : OutlinedButton.icon( + statesController: controller, + onPressed: () { }, + icon: icon, + label: const Text('button'), + ), ), ), ); @@ -1765,7 +1772,7 @@ void main() { expect(controller.value, {}); expect(count, 0); - final Offset center = tester.getCenter(find.byType(OutlinedButton)); + final Offset center = tester.getCenter(find.byType(Text)); final TestGesture gesture = await tester.createGesture( kind: PointerDeviceKind.mouse, ); @@ -1816,24 +1823,37 @@ void main() { await tester.pumpWidget( MaterialApp( home: Center( - child: OutlinedButton( - statesController: controller, - onPressed: null, - child: const Text('button'), - ), + child: icon == null + ? OutlinedButton( + statesController: controller, + onPressed: null, + child: const Text('button'), + ) + : OutlinedButton.icon( + statesController: controller, + onPressed: null, + icon: icon, + label: const Text('button'), + ), ), ), ); await tester.pumpAndSettle(); expect(controller.value, {MaterialState.hovered, MaterialState.disabled}); expect(count, 10); // removes pressed and adds disabled - two changes - await gesture.moveTo(Offset.zero); await tester.pumpAndSettle(); expect(controller.value, {MaterialState.disabled}); expect(count, 11); - await gesture.removePointer(); + } + + testWidgets('OutlinedButton statesController', (WidgetTester tester) async { + testStatesController(null, tester); + }); + + testWidgets('OutlinedButton.icon statesController', (WidgetTester tester) async { + testStatesController(const Icon(Icons.add), tester); }); testWidgets('Disabled OutlinedButton statesController', (WidgetTester tester) async { diff --git a/packages/flutter/test/material/text_button_test.dart b/packages/flutter/test/material/text_button_test.dart index cc4c67d85e..a27de2a0b7 100644 --- a/packages/flutter/test/material/text_button_test.dart +++ b/packages/flutter/test/material/text_button_test.dart @@ -1549,7 +1549,7 @@ void main() { expect(material.textStyle!.color, Colors.white); }); - testWidgets('TextButton statesController', (WidgetTester tester) async { + Future testStatesController(Widget? icon, WidgetTester tester) async { int count = 0; void valueChanged() { count += 1; @@ -1560,11 +1560,18 @@ void main() { await tester.pumpWidget( MaterialApp( home: Center( - child: TextButton( - statesController: controller, - onPressed: () { }, - child: const Text('button'), - ), + child: icon == null + ? TextButton( + statesController: controller, + onPressed: () { }, + child: const Text('button'), + ) + : TextButton.icon( + statesController: controller, + onPressed: () { }, + icon: icon, + label: const Text('button'), + ), ), ), ); @@ -1572,7 +1579,7 @@ void main() { expect(controller.value, {}); expect(count, 0); - final Offset center = tester.getCenter(find.byType(TextButton)); + final Offset center = tester.getCenter(find.byType(Text)); final TestGesture gesture = await tester.createGesture( kind: PointerDeviceKind.mouse, ); @@ -1623,24 +1630,37 @@ void main() { await tester.pumpWidget( MaterialApp( home: Center( - child: TextButton( - statesController: controller, - onPressed: null, - child: const Text('button'), - ), + child: icon == null + ? TextButton( + statesController: controller, + onPressed: null, + child: const Text('button'), + ) + : TextButton.icon( + statesController: controller, + onPressed: null, + icon: icon, + label: const Text('button'), + ), ), ), ); await tester.pumpAndSettle(); expect(controller.value, {MaterialState.hovered, MaterialState.disabled}); expect(count, 10); // removes pressed and adds disabled - two changes - await gesture.moveTo(Offset.zero); await tester.pumpAndSettle(); expect(controller.value, {MaterialState.disabled}); expect(count, 11); - await gesture.removePointer(); + } + + testWidgets('TextButton statesController', (WidgetTester tester) async { + testStatesController(null, tester); + }); + + testWidgets('TextButton.icon statesController', (WidgetTester tester) async { + testStatesController(const Icon(Icons.add), tester); }); testWidgets('Disabled TextButton statesController', (WidgetTester tester) async {