Update OutlineButton on-pressed fill color (#27519)
This commit is contained in:
parent
965dc52e2e
commit
dfa489c394
@ -343,10 +343,7 @@ class _OutlineButtonState extends State<_OutlineButton> with SingleTickerProvide
|
|||||||
}
|
}
|
||||||
|
|
||||||
Color _getFillColor() {
|
Color _getFillColor() {
|
||||||
final bool themeIsDark = widget.brightness == Brightness.dark;
|
final Color color = widget.color ?? Theme.of(context).canvasColor;
|
||||||
final Color color = widget.color ?? (themeIsDark
|
|
||||||
? const Color(0x00000000)
|
|
||||||
: const Color(0x00FFFFFF));
|
|
||||||
final Tween<Color> colorTween = ColorTween(
|
final Tween<Color> colorTween = ColorTween(
|
||||||
begin: color.withAlpha(0x00),
|
begin: color.withAlpha(0x00),
|
||||||
end: color.withAlpha(0xFF),
|
end: color.withAlpha(0xFF),
|
||||||
|
@ -121,7 +121,7 @@ void main() {
|
|||||||
// Wait for the border color to change from disabled to enabled.
|
// Wait for the border color to change from disabled to enabled.
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
// Expect that the button is disabled and painted with the enabled border color.
|
// Expect that the button is enabled and painted with the enabled border color.
|
||||||
expect(tester.widget<OutlineButton>(outlineButton).enabled, true);
|
expect(tester.widget<OutlineButton>(outlineButton).enabled, true);
|
||||||
expect(
|
expect(
|
||||||
outlineButton,
|
outlineButton,
|
||||||
@ -314,4 +314,63 @@ void main() {
|
|||||||
'splashColor: Color(0xff9e9e9e)',
|
'splashColor: Color(0xff9e9e9e)',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('OutlineButton pressed fillColor default', (WidgetTester tester) async {
|
||||||
|
Widget buildFrame(ThemeData theme) {
|
||||||
|
return MaterialApp(
|
||||||
|
theme: theme,
|
||||||
|
home: Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: OutlineButton(
|
||||||
|
onPressed: () {},
|
||||||
|
child: const Text('Hello'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await tester.pumpWidget(buildFrame(ThemeData.dark()));
|
||||||
|
final Finder button = find.byType(OutlineButton);
|
||||||
|
final Offset center = tester.getCenter(button);
|
||||||
|
|
||||||
|
// Default value for dark Theme.of(context).canvasColor as well as
|
||||||
|
// the OutlineButton fill color when the button has been pressed.
|
||||||
|
Color fillColor = Colors.grey[850];
|
||||||
|
|
||||||
|
// Initially the interior of the button is transparent.
|
||||||
|
expect(button, paints..path(color: fillColor.withAlpha(0x00)));
|
||||||
|
|
||||||
|
// Tap-press gesture on the button triggers the fill animation.
|
||||||
|
TestGesture gesture = await tester.startGesture(center);
|
||||||
|
await tester.pump(); // Start the button fill animation.
|
||||||
|
await tester.pump(const Duration(milliseconds: 200)); // Animation is complete.
|
||||||
|
expect(button, paints..path(color: fillColor.withAlpha(0xFF)));
|
||||||
|
|
||||||
|
// Tap gesture completes, button returns to its initial configuration.
|
||||||
|
await gesture.up();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(button, paints..path(color: fillColor.withAlpha(0x00)));
|
||||||
|
|
||||||
|
await tester.pumpWidget(buildFrame(ThemeData.light()));
|
||||||
|
await tester.pumpAndSettle(); // Finish the theme change animation.
|
||||||
|
|
||||||
|
// Default value for light Theme.of(context).canvasColor as well as
|
||||||
|
// the OutlineButton fill color when the button has been pressed.
|
||||||
|
fillColor = Colors.grey[50];
|
||||||
|
|
||||||
|
// Initially the interior of the button is transparent.
|
||||||
|
expect(button, paints..path(color: fillColor.withAlpha(0x00)));
|
||||||
|
|
||||||
|
// Tap-press gesture on the button triggers the fill animation.
|
||||||
|
gesture = await tester.startGesture(center);
|
||||||
|
await tester.pump(); // Start the button fill animation.
|
||||||
|
await tester.pump(const Duration(milliseconds: 200)); // Animation is complete.
|
||||||
|
expect(button, paints..path(color: fillColor.withAlpha(0xFF)));
|
||||||
|
|
||||||
|
// Tap gesture completes, button returns to its initial configuration.
|
||||||
|
await gesture.up();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(button, paints..path(color: fillColor.withAlpha(0x00)));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ void main() {
|
|||||||
|
|
||||||
final RawMaterialButton raw = tester.widget<RawMaterialButton>(find.byType(RawMaterialButton));
|
final RawMaterialButton raw = tester.widget<RawMaterialButton>(find.byType(RawMaterialButton));
|
||||||
expect(raw.textStyle.color, const Color(0xdd000000));
|
expect(raw.textStyle.color, const Color(0xdd000000));
|
||||||
expect(raw.fillColor, const Color(0x00ffffff));
|
expect(raw.fillColor, const Color(0x00fafafa));
|
||||||
expect(raw.highlightColor, const Color(0x29000000)); // Was Color(0x66bcbcbc)
|
expect(raw.highlightColor, const Color(0x29000000)); // Was Color(0x66bcbcbc)
|
||||||
expect(raw.splashColor, const Color(0x1f000000)); // Was Color(0x66c8c8c8)
|
expect(raw.splashColor, const Color(0x1f000000)); // Was Color(0x66c8c8c8)
|
||||||
expect(raw.elevation, 0.0);
|
expect(raw.elevation, 0.0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user