Unverified Commit 4b902c79 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

CupertinoButton: Add clickable cursor on web (#96863)

parent d61caaad
...@@ -245,43 +245,46 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv ...@@ -245,43 +245,46 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv
final TextStyle textStyle = themeData.textTheme.textStyle.copyWith(color: foregroundColor); final TextStyle textStyle = themeData.textTheme.textStyle.copyWith(color: foregroundColor);
return GestureDetector( return MouseRegion(
behavior: HitTestBehavior.opaque, cursor: enabled && kIsWeb ? SystemMouseCursors.click : MouseCursor.defer,
onTapDown: enabled ? _handleTapDown : null, child: GestureDetector(
onTapUp: enabled ? _handleTapUp : null, behavior: HitTestBehavior.opaque,
onTapCancel: enabled ? _handleTapCancel : null, onTapDown: enabled ? _handleTapDown : null,
onTap: widget.onPressed, onTapUp: enabled ? _handleTapUp : null,
child: Semantics( onTapCancel: enabled ? _handleTapCancel : null,
button: true, onTap: widget.onPressed,
child: ConstrainedBox( child: Semantics(
constraints: widget.minSize == null button: true,
? const BoxConstraints() child: ConstrainedBox(
: BoxConstraints( constraints: widget.minSize == null
minWidth: widget.minSize!, ? const BoxConstraints()
minHeight: widget.minSize!, : BoxConstraints(
), minWidth: widget.minSize!,
child: FadeTransition( minHeight: widget.minSize!,
opacity: _opacityAnimation, ),
child: DecoratedBox( child: FadeTransition(
decoration: BoxDecoration( opacity: _opacityAnimation,
borderRadius: widget.borderRadius, child: DecoratedBox(
color: backgroundColor != null && !enabled decoration: BoxDecoration(
? CupertinoDynamicColor.resolve(widget.disabledColor, context) borderRadius: widget.borderRadius,
: backgroundColor, color: backgroundColor != null && !enabled
), ? CupertinoDynamicColor.resolve(widget.disabledColor, context)
child: Padding( : backgroundColor,
padding: widget.padding ?? (backgroundColor != null ),
? _kBackgroundButtonPadding child: Padding(
: _kButtonPadding), padding: widget.padding ?? (backgroundColor != null
child: Align( ? _kBackgroundButtonPadding
alignment: widget.alignment, : _kButtonPadding),
widthFactor: 1.0, child: Align(
heightFactor: 1.0, alignment: widget.alignment,
child: DefaultTextStyle( widthFactor: 1.0,
style: textStyle, heightFactor: 1.0,
child: IconTheme( child: DefaultTextStyle(
data: IconThemeData(color: foregroundColor), style: textStyle,
child: widget.child, child: IconTheme(
data: IconThemeData(color: foregroundColor),
child: widget.child,
),
), ),
), ),
), ),
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -451,6 +453,33 @@ void main() { ...@@ -451,6 +453,33 @@ void main() {
).decoration as BoxDecoration; ).decoration as BoxDecoration;
expect(decoration.color, isSameColorAs(CupertinoColors.systemBlue.darkColor)); expect(decoration.color, isSameColorAs(CupertinoColors.systemBlue.darkColor));
}); });
testWidgets('Hovering over Cupertino button updates cursor to clickable on Web', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: CupertinoButton.filled(
onPressed: () { },
child: const Text('Tap me'),
),
),
),
);
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
await gesture.addPointer(location: const Offset(10, 10));
await tester.pumpAndSettle();
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
final Offset button = tester.getCenter(find.byType(CupertinoButton));
await gesture.moveTo(button);
addTearDown(gesture.removePointer);
await tester.pumpAndSettle();
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
kIsWeb ? SystemMouseCursors.click : SystemMouseCursors.basic,
);
});
} }
Widget boilerplate({ required Widget child }) { Widget boilerplate({ required Widget child }) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment