Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
0a178f85
Unverified
Commit
0a178f85
authored
Apr 12, 2022
by
Taha Tesser
Committed by
GitHub
Apr 12, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`CupertinoContextMenu`/`ContextMenuAction`: Add clickable cursor for web (#99519)
parent
6def1596
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
47 deletions
+118
-47
context_menu.dart
packages/flutter/lib/src/cupertino/context_menu.dart
+15
-11
context_menu_action.dart
packages/flutter/lib/src/cupertino/context_menu_action.dart
+40
-36
context_menu_action_test.dart
...ages/flutter/test/cupertino/context_menu_action_test.dart
+28
-0
context_menu_test.dart
packages/flutter/test/cupertino/context_menu_test.dart
+35
-0
No files found.
packages/flutter/lib/src/cupertino/context_menu.dart
View file @
0a178f85
...
...
@@ -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,17 +368,20 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
@override
Widget
build
(
BuildContext
context
)
{
return
GestureDetector
(
onTapCancel:
_onTapCancel
,
onTapDown:
_onTapDown
,
onTapUp:
_onTapUp
,
onTap:
_onTap
,
child:
TickerMode
(
enabled:
!
_childHidden
,
child:
Opacity
(
key:
_childGlobalKey
,
opacity:
_childHidden
?
0.0
:
1.0
,
child:
widget
.
child
,
return
MouseRegion
(
cursor:
kIsWeb
?
SystemMouseCursors
.
click
:
MouseCursor
.
defer
,
child:
GestureDetector
(
onTapCancel:
_onTapCancel
,
onTapDown:
_onTapDown
,
onTapUp:
_onTapUp
,
onTap:
_onTap
,
child:
TickerMode
(
enabled:
!
_childHidden
,
child:
Opacity
(
key:
_childGlobalKey
,
opacity:
_childHidden
?
0.0
:
1.0
,
child:
widget
.
child
,
),
),
),
);
...
...
packages/flutter/lib/src/cupertino/context_menu_action.dart
View file @
0a178f85
...
...
@@ -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,43 +107,46 @@ class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction>
@override
Widget
build
(
BuildContext
context
)
{
return
GestureDetector
(
key:
_globalKey
,
onTapDown:
onTapDown
,
onTapUp:
onTapUp
,
onTapCancel:
onTapCancel
,
onTap:
widget
.
onPressed
,
behavior:
HitTestBehavior
.
opaque
,
child:
ConstrainedBox
(
constraints:
const
BoxConstraints
(
minHeight:
_kButtonHeight
,
),
child:
Semantics
(
button:
true
,
child:
Container
(
decoration:
BoxDecoration
(
color:
_isPressed
?
CupertinoDynamicColor
.
resolve
(
_kBackgroundColorPressed
,
context
)
:
CupertinoDynamicColor
.
resolve
(
_kBackgroundColor
,
context
),
),
padding:
const
EdgeInsets
.
symmetric
(
vertical:
16.0
,
horizontal:
10.0
,
),
child:
DefaultTextStyle
(
style:
_textStyle
,
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
children:
<
Widget
>[
Flexible
(
child:
widget
.
child
,
),
if
(
widget
.
trailingIcon
!=
null
)
Icon
(
widget
.
trailingIcon
,
color:
_textStyle
.
color
,
return
MouseRegion
(
cursor:
widget
.
onPressed
!=
null
&&
kIsWeb
?
SystemMouseCursors
.
click
:
MouseCursor
.
defer
,
child:
GestureDetector
(
key:
_globalKey
,
onTapDown:
onTapDown
,
onTapUp:
onTapUp
,
onTapCancel:
onTapCancel
,
onTap:
widget
.
onPressed
,
behavior:
HitTestBehavior
.
opaque
,
child:
ConstrainedBox
(
constraints:
const
BoxConstraints
(
minHeight:
_kButtonHeight
,
),
child:
Semantics
(
button:
true
,
child:
Container
(
decoration:
BoxDecoration
(
color:
_isPressed
?
CupertinoDynamicColor
.
resolve
(
_kBackgroundColorPressed
,
context
)
:
CupertinoDynamicColor
.
resolve
(
_kBackgroundColor
,
context
),
),
padding:
const
EdgeInsets
.
symmetric
(
vertical:
16.0
,
horizontal:
10.0
,
),
child:
DefaultTextStyle
(
style:
_textStyle
,
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
children:
<
Widget
>[
Flexible
(
child:
widget
.
child
,
),
],
if
(
widget
.
trailingIcon
!=
null
)
Icon
(
widget
.
trailingIcon
,
color:
_textStyle
.
color
,
),
],
),
),
),
),
...
...
packages/flutter/test/cupertino/context_menu_action_test.dart
View file @
0a178f85
...
...
@@ -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
,
);
});
}
packages/flutter/test/cupertino/context_menu_test.dart
View file @
0a178f85
...
...
@@ -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'
,
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment