mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
CupertinoButton: Add clickable cursor on web (#96863)
This commit is contained in:
parent
d61caaad26
commit
4b902c79ce
@ -245,43 +245,46 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv
|
||||
|
||||
final TextStyle textStyle = themeData.textTheme.textStyle.copyWith(color: foregroundColor);
|
||||
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTapDown: enabled ? _handleTapDown : null,
|
||||
onTapUp: enabled ? _handleTapUp : null,
|
||||
onTapCancel: enabled ? _handleTapCancel : null,
|
||||
onTap: widget.onPressed,
|
||||
child: Semantics(
|
||||
button: true,
|
||||
child: ConstrainedBox(
|
||||
constraints: widget.minSize == null
|
||||
? const BoxConstraints()
|
||||
: BoxConstraints(
|
||||
minWidth: widget.minSize!,
|
||||
minHeight: widget.minSize!,
|
||||
),
|
||||
child: FadeTransition(
|
||||
opacity: _opacityAnimation,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: widget.borderRadius,
|
||||
color: backgroundColor != null && !enabled
|
||||
? CupertinoDynamicColor.resolve(widget.disabledColor, context)
|
||||
: backgroundColor,
|
||||
),
|
||||
child: Padding(
|
||||
padding: widget.padding ?? (backgroundColor != null
|
||||
? _kBackgroundButtonPadding
|
||||
: _kButtonPadding),
|
||||
child: Align(
|
||||
alignment: widget.alignment,
|
||||
widthFactor: 1.0,
|
||||
heightFactor: 1.0,
|
||||
child: DefaultTextStyle(
|
||||
style: textStyle,
|
||||
child: IconTheme(
|
||||
data: IconThemeData(color: foregroundColor),
|
||||
child: widget.child,
|
||||
return MouseRegion(
|
||||
cursor: enabled && kIsWeb ? SystemMouseCursors.click : MouseCursor.defer,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTapDown: enabled ? _handleTapDown : null,
|
||||
onTapUp: enabled ? _handleTapUp : null,
|
||||
onTapCancel: enabled ? _handleTapCancel : null,
|
||||
onTap: widget.onPressed,
|
||||
child: Semantics(
|
||||
button: true,
|
||||
child: ConstrainedBox(
|
||||
constraints: widget.minSize == null
|
||||
? const BoxConstraints()
|
||||
: BoxConstraints(
|
||||
minWidth: widget.minSize!,
|
||||
minHeight: widget.minSize!,
|
||||
),
|
||||
child: FadeTransition(
|
||||
opacity: _opacityAnimation,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: widget.borderRadius,
|
||||
color: backgroundColor != null && !enabled
|
||||
? CupertinoDynamicColor.resolve(widget.disabledColor, context)
|
||||
: backgroundColor,
|
||||
),
|
||||
child: Padding(
|
||||
padding: widget.padding ?? (backgroundColor != null
|
||||
? _kBackgroundButtonPadding
|
||||
: _kButtonPadding),
|
||||
child: Align(
|
||||
alignment: widget.alignment,
|
||||
widthFactor: 1.0,
|
||||
heightFactor: 1.0,
|
||||
child: DefaultTextStyle(
|
||||
style: textStyle,
|
||||
child: IconTheme(
|
||||
data: IconThemeData(color: foregroundColor),
|
||||
child: widget.child,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@ -451,6 +453,33 @@ void main() {
|
||||
).decoration as BoxDecoration;
|
||||
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 }) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user