Fix OutlinedButton
, TextButton
, and IconButton
throw exception when passing only one cursor to styleFrom
(#125204)
fixes https://github.com/flutter/flutter/issues/118071
This commit is contained in:
parent
b7332ef10a
commit
38c7c2fe93
@ -207,9 +207,7 @@ class ElevatedButton extends ButtonStyleButton {
|
|||||||
final MaterialStateProperty<double>? elevationValue = (elevation == null)
|
final MaterialStateProperty<double>? elevationValue = (elevation == null)
|
||||||
? null
|
? null
|
||||||
: _ElevatedButtonDefaultElevation(elevation);
|
: _ElevatedButtonDefaultElevation(elevation);
|
||||||
final MaterialStateProperty<MouseCursor?>? mouseCursor = (enabledMouseCursor == null && disabledMouseCursor == null)
|
final MaterialStateProperty<MouseCursor?> mouseCursor = _ElevatedButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor);
|
||||||
? null
|
|
||||||
: _ElevatedButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor);
|
|
||||||
|
|
||||||
return ButtonStyle(
|
return ButtonStyle(
|
||||||
textStyle: MaterialStatePropertyAll<TextStyle?>(textStyle),
|
textStyle: MaterialStatePropertyAll<TextStyle?>(textStyle),
|
||||||
|
@ -240,10 +240,7 @@ class FilledButton extends ButtonStyleButton {
|
|||||||
final MaterialStateProperty<Color?>? overlayColor = (foreground == null)
|
final MaterialStateProperty<Color?>? overlayColor = (foreground == null)
|
||||||
? null
|
? null
|
||||||
: _FilledButtonDefaultOverlay(foreground);
|
: _FilledButtonDefaultOverlay(foreground);
|
||||||
final MaterialStateProperty<MouseCursor?>? mouseCursor =
|
final MaterialStateProperty<MouseCursor?> mouseCursor = _FilledButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor);
|
||||||
(enabledMouseCursor == null && disabledMouseCursor == null)
|
|
||||||
? null
|
|
||||||
: _FilledButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor);
|
|
||||||
|
|
||||||
return ButtonStyle(
|
return ButtonStyle(
|
||||||
textStyle: MaterialStatePropertyAll<TextStyle?>(textStyle),
|
textStyle: MaterialStatePropertyAll<TextStyle?>(textStyle),
|
||||||
|
@ -638,9 +638,7 @@ class IconButton extends StatelessWidget {
|
|||||||
final MaterialStateProperty<Color?>? overlayColor = (foregroundColor == null && hoverColor == null && focusColor == null && highlightColor == null)
|
final MaterialStateProperty<Color?>? overlayColor = (foregroundColor == null && hoverColor == null && focusColor == null && highlightColor == null)
|
||||||
? null
|
? null
|
||||||
: _IconButtonDefaultOverlay(foregroundColor, focusColor, hoverColor, highlightColor);
|
: _IconButtonDefaultOverlay(foregroundColor, focusColor, hoverColor, highlightColor);
|
||||||
final MaterialStateProperty<MouseCursor>? mouseCursor = (enabledMouseCursor == null && disabledMouseCursor == null)
|
final MaterialStateProperty<MouseCursor?> mouseCursor = _IconButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor);
|
||||||
? null
|
|
||||||
: _IconButtonDefaultMouseCursor(enabledMouseCursor!, disabledMouseCursor!);
|
|
||||||
|
|
||||||
return ButtonStyle(
|
return ButtonStyle(
|
||||||
backgroundColor: buttonBackgroundColor,
|
backgroundColor: buttonBackgroundColor,
|
||||||
@ -1061,14 +1059,14 @@ class _IconButtonDefaultOverlay extends MaterialStateProperty<Color?> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class _IconButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor> with Diagnosticable {
|
class _IconButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor?> with Diagnosticable {
|
||||||
_IconButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor);
|
_IconButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor);
|
||||||
|
|
||||||
final MouseCursor enabledCursor;
|
final MouseCursor? enabledCursor;
|
||||||
final MouseCursor disabledCursor;
|
final MouseCursor? disabledCursor;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MouseCursor resolve(Set<MaterialState> states) {
|
MouseCursor? resolve(Set<MaterialState> states) {
|
||||||
if (states.contains(MaterialState.disabled)) {
|
if (states.contains(MaterialState.disabled)) {
|
||||||
return disabledCursor;
|
return disabledCursor;
|
||||||
}
|
}
|
||||||
|
@ -186,9 +186,7 @@ class OutlinedButton extends ButtonStyleButton {
|
|||||||
final MaterialStateProperty<Color?>? overlayColor = (foreground == null)
|
final MaterialStateProperty<Color?>? overlayColor = (foreground == null)
|
||||||
? null
|
? null
|
||||||
: _OutlinedButtonDefaultOverlay(foreground);
|
: _OutlinedButtonDefaultOverlay(foreground);
|
||||||
final MaterialStateProperty<MouseCursor>? mouseCursor = (enabledMouseCursor == null && disabledMouseCursor == null)
|
final MaterialStateProperty<MouseCursor?> mouseCursor = _OutlinedButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor);
|
||||||
? null
|
|
||||||
: _OutlinedButtonDefaultMouseCursor(enabledMouseCursor!, disabledMouseCursor!);
|
|
||||||
|
|
||||||
return ButtonStyle(
|
return ButtonStyle(
|
||||||
textStyle: ButtonStyleButton.allOrNull<TextStyle>(textStyle),
|
textStyle: ButtonStyleButton.allOrNull<TextStyle>(textStyle),
|
||||||
@ -395,14 +393,14 @@ class _OutlinedButtonDefaultOverlay extends MaterialStateProperty<Color?> with D
|
|||||||
}
|
}
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class _OutlinedButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor> with Diagnosticable {
|
class _OutlinedButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor?> with Diagnosticable {
|
||||||
_OutlinedButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor);
|
_OutlinedButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor);
|
||||||
|
|
||||||
final MouseCursor enabledCursor;
|
final MouseCursor? enabledCursor;
|
||||||
final MouseCursor disabledCursor;
|
final MouseCursor? disabledCursor;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MouseCursor resolve(Set<MaterialState> states) {
|
MouseCursor? resolve(Set<MaterialState> states) {
|
||||||
if (states.contains(MaterialState.disabled)) {
|
if (states.contains(MaterialState.disabled)) {
|
||||||
return disabledCursor;
|
return disabledCursor;
|
||||||
}
|
}
|
||||||
|
@ -200,9 +200,7 @@ class TextButton extends ButtonStyleButton {
|
|||||||
: disabledIconColor == null
|
: disabledIconColor == null
|
||||||
? ButtonStyleButton.allOrNull<Color?>(iconColor)
|
? ButtonStyleButton.allOrNull<Color?>(iconColor)
|
||||||
: _TextButtonDefaultIconColor(iconColor, disabledIconColor);
|
: _TextButtonDefaultIconColor(iconColor, disabledIconColor);
|
||||||
final MaterialStateProperty<MouseCursor>? mouseCursor = (enabledMouseCursor == null && disabledMouseCursor == null)
|
final MaterialStateProperty<MouseCursor?> mouseCursor = _TextButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor);
|
||||||
? null
|
|
||||||
: _TextButtonDefaultMouseCursor(enabledMouseCursor!, disabledMouseCursor!);
|
|
||||||
|
|
||||||
return ButtonStyle(
|
return ButtonStyle(
|
||||||
textStyle: ButtonStyleButton.allOrNull<TextStyle>(textStyle),
|
textStyle: ButtonStyleButton.allOrNull<TextStyle>(textStyle),
|
||||||
@ -456,14 +454,14 @@ class _TextButtonDefaultIconColor extends MaterialStateProperty<Color?> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class _TextButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor> with Diagnosticable {
|
class _TextButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor?> with Diagnosticable {
|
||||||
_TextButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor);
|
_TextButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor);
|
||||||
|
|
||||||
final MouseCursor enabledCursor;
|
final MouseCursor? enabledCursor;
|
||||||
final MouseCursor disabledCursor;
|
final MouseCursor? disabledCursor;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MouseCursor resolve(Set<MaterialState> states) {
|
MouseCursor? resolve(Set<MaterialState> states) {
|
||||||
if (states.contains(MaterialState.disabled)) {
|
if (states.contains(MaterialState.disabled)) {
|
||||||
return disabledCursor;
|
return disabledCursor;
|
||||||
}
|
}
|
||||||
|
@ -1835,7 +1835,6 @@ void main() {
|
|||||||
expect(controller.value, <MaterialState>{MaterialState.disabled});
|
expect(controller.value, <MaterialState>{MaterialState.disabled});
|
||||||
expect(count, 1);
|
expect(count, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextStyle _iconStyle(WidgetTester tester, IconData icon) {
|
TextStyle _iconStyle(WidgetTester tester, IconData icon) {
|
||||||
|
@ -2482,6 +2482,26 @@ void main() {
|
|||||||
testWidgets('black87 icon color defined by users shows correctly in Material3', (WidgetTester tester) async {
|
testWidgets('black87 icon color defined by users shows correctly in Material3', (WidgetTester tester) async {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets("IconButton.styleFrom doesn't throw exception on passing only one cursor", (WidgetTester tester) async {
|
||||||
|
// This is a regression test for https://github.com/flutter/flutter/issues/118071.
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Material(
|
||||||
|
child: IconButton(
|
||||||
|
style: OutlinedButton.styleFrom(
|
||||||
|
enabledMouseCursor: SystemMouseCursors.text,
|
||||||
|
),
|
||||||
|
onPressed: () {},
|
||||||
|
icon: const Icon(Icons.add),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1947,6 +1947,24 @@ void main() {
|
|||||||
expect(controller.value, <MaterialState>{MaterialState.disabled});
|
expect(controller.value, <MaterialState>{MaterialState.disabled});
|
||||||
expect(count, 1);
|
expect(count, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets("OutlinedButton.styleFrom doesn't throw exception on passing only one cursor", (WidgetTester tester) async {
|
||||||
|
// This is a regression test for https://github.com/flutter/flutter/issues/118071.
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: OutlinedButton(
|
||||||
|
style: OutlinedButton.styleFrom(
|
||||||
|
enabledMouseCursor: SystemMouseCursors.text,
|
||||||
|
),
|
||||||
|
onPressed: () {},
|
||||||
|
child: const Text('button'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
TextStyle _iconStyle(WidgetTester tester, IconData icon) {
|
TextStyle _iconStyle(WidgetTester tester, IconData icon) {
|
||||||
|
@ -1809,6 +1809,24 @@ void main() {
|
|||||||
expect(material.textStyle!.color, colorScheme.onSurface.withOpacity(0.38));
|
expect(material.textStyle!.color, colorScheme.onSurface.withOpacity(0.38));
|
||||||
expect(iconColor(), equals(Colors.blue));
|
expect(iconColor(), equals(Colors.blue));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets("TextButton.styleFrom doesn't throw exception on passing only one cursor", (WidgetTester tester) async {
|
||||||
|
// This is a regression test for https://github.com/flutter/flutter/issues/118071.
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: TextButton(
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
enabledMouseCursor: SystemMouseCursors.text,
|
||||||
|
),
|
||||||
|
onPressed: () {},
|
||||||
|
child: const Text('button'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
TextStyle? _iconStyle(WidgetTester tester, IconData icon) {
|
TextStyle? _iconStyle(WidgetTester tester, IconData icon) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user