CupertinoContextMenu
/ContextMenuAction
: Add clickable cursor for web (#99519)
This commit is contained in:
parent
6def1596cd
commit
0a178f858d
@ -4,6 +4,7 @@
|
||||
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' as ui;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart' show kMinFlingVelocity, kLongPressTimeout;
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@ -367,7 +368,9 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
return MouseRegion(
|
||||
cursor: kIsWeb ? SystemMouseCursors.click : MouseCursor.defer,
|
||||
child: GestureDetector(
|
||||
onTapCancel: _onTapCancel,
|
||||
onTapDown: _onTapDown,
|
||||
onTapUp: _onTapUp,
|
||||
@ -380,6 +383,7 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
|
||||
child: widget.child,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'colors.dart';
|
||||
|
||||
@ -106,7 +107,9 @@ class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
return MouseRegion(
|
||||
cursor: widget.onPressed != null && kIsWeb ? SystemMouseCursors.click : MouseCursor.defer,
|
||||
child: GestureDetector(
|
||||
key: _globalKey,
|
||||
onTapDown: onTapDown,
|
||||
onTapUp: onTapUp,
|
||||
@ -148,6 +151,7 @@ class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction>
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,9 @@
|
||||
// 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_test/flutter_test.dart';
|
||||
|
||||
import '../rendering/mock_canvas.dart';
|
||||
@ -122,4 +125,29 @@ void main() {
|
||||
expect(_getTextStyle(tester).fontWeight, kDefaultActionWeight);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Hovering over Cupertino context menu action updates cursor to clickable on Web',
|
||||
(WidgetTester tester) async {
|
||||
/// Cupertino context menu action without "onPressed" callback.
|
||||
await tester.pumpWidget(_getApp());
|
||||
final Offset contextMenuAction = tester.getCenter(find.text('I am a CupertinoContextMenuAction'));
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
|
||||
await gesture.addPointer(location: contextMenuAction);
|
||||
await tester.pumpAndSettle();
|
||||
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
|
||||
|
||||
// / Cupertino context menu action with "onPressed" callback.
|
||||
await tester.pumpWidget(_getApp(onPressed: (){}));
|
||||
await gesture.moveTo(const Offset(10, 10));
|
||||
await tester.pumpAndSettle();
|
||||
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
|
||||
|
||||
await gesture.moveTo(contextMenuAction);
|
||||
addTearDown(gesture.removePointer);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
kIsWeb ? SystemMouseCursors.click : SystemMouseCursors.basic,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -3,6 +3,9 @@
|
||||
// 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_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
@ -193,6 +196,38 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(_findStatic(), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Hovering over Cupertino context menu updates cursor to clickable on Web', (WidgetTester tester) async {
|
||||
final Widget child = _getChild();
|
||||
await tester.pumpWidget(CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: Center(
|
||||
child: CupertinoContextMenu(
|
||||
actions: const <CupertinoContextMenuAction>[
|
||||
CupertinoContextMenuAction(
|
||||
child: Text('CupertinoContextMenuAction One'),
|
||||
),
|
||||
],
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
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 contextMenu = tester.getCenter(find.byWidget(child));
|
||||
await gesture.moveTo(contextMenu);
|
||||
addTearDown(gesture.removePointer);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
kIsWeb ? SystemMouseCursors.click : SystemMouseCursors.basic,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('CupertinoContextMenu when open', () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user