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
4cea5ee0
Unverified
Commit
4cea5ee0
authored
Mar 21, 2022
by
Taha Tesser
Committed by
GitHub
Mar 21, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`CupertinoSwitch`: Add clickable cursor for web (#99554)
parent
7b8135af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
12 deletions
+74
-12
switch.dart
packages/flutter/lib/src/cupertino/switch.dart
+15
-12
switch_test.dart
packages/flutter/test/cupertino/switch_test.dart
+59
-0
No files found.
packages/flutter/lib/src/cupertino/switch.dart
View file @
4cea5ee0
...
...
@@ -298,19 +298,22 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt
Widget
build
(
BuildContext
context
)
{
if
(
needsPositionAnimation
)
_resumePositionAnimation
();
return
Opacity
(
opacity:
widget
.
onChanged
==
null
?
_kCupertinoSwitchDisabledOpacity
:
1.0
,
child:
_CupertinoSwitchRenderObjectWidget
(
value:
widget
.
value
,
activeColor:
CupertinoDynamicColor
.
resolve
(
widget
.
activeColor
??
CupertinoColors
.
systemGreen
,
context
,
return
MouseRegion
(
cursor:
isInteractive
&&
kIsWeb
?
SystemMouseCursors
.
click
:
MouseCursor
.
defer
,
child:
Opacity
(
opacity:
widget
.
onChanged
==
null
?
_kCupertinoSwitchDisabledOpacity
:
1.0
,
child:
_CupertinoSwitchRenderObjectWidget
(
value:
widget
.
value
,
activeColor:
CupertinoDynamicColor
.
resolve
(
widget
.
activeColor
??
CupertinoColors
.
systemGreen
,
context
,
),
trackColor:
CupertinoDynamicColor
.
resolve
(
widget
.
trackColor
??
CupertinoColors
.
secondarySystemFill
,
context
),
thumbColor:
CupertinoDynamicColor
.
resolve
(
widget
.
thumbColor
??
CupertinoColors
.
white
,
context
),
onChanged:
widget
.
onChanged
,
textDirection:
Directionality
.
of
(
context
),
state:
this
,
),
trackColor:
CupertinoDynamicColor
.
resolve
(
widget
.
trackColor
??
CupertinoColors
.
secondarySystemFill
,
context
),
thumbColor:
CupertinoDynamicColor
.
resolve
(
widget
.
thumbColor
??
CupertinoColors
.
white
,
context
),
onChanged:
widget
.
onChanged
,
textDirection:
Directionality
.
of
(
context
),
state:
this
,
),
);
}
...
...
packages/flutter/test/cupertino/switch_test.dart
View file @
4cea5ee0
...
...
@@ -7,8 +7,10 @@
@Tags
(<
String
>[
'reduced-test-set'
])
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
...
...
@@ -761,4 +763,61 @@ void main() {
matchesGoldenFile
(
'switch.tap.on.dark.png'
),
);
});
testWidgets
(
'Hovering over Cupertino switch updates cursor to clickable on Web'
,
(
WidgetTester
tester
)
async
{
const
bool
value
=
false
;
// Disabled CupertinoSwitch does not update cursor on Web.
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
const
Center
(
child:
CupertinoSwitch
(
value:
value
,
dragStartBehavior:
DragStartBehavior
.
down
,
onChanged:
null
,
),
);
},
),
),
);
final
TestGesture
gesture
=
await
tester
.
createGesture
(
kind:
PointerDeviceKind
.
mouse
,
pointer:
1
);
final
Offset
cupertinoSwitch
=
tester
.
getCenter
(
find
.
byType
(
CupertinoSwitch
));
await
gesture
.
addPointer
(
location:
cupertinoSwitch
);
await
tester
.
pumpAndSettle
();
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
basic
);
// Enabled CupertinoSwitch updates cursor when hovering on Web.
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
Center
(
child:
CupertinoSwitch
(
value:
value
,
dragStartBehavior:
DragStartBehavior
.
down
,
onChanged:
(
bool
newValue
)
{
},
),
);
},
),
),
);
await
gesture
.
moveTo
(
const
Offset
(
10
,
10
));
await
tester
.
pumpAndSettle
();
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
basic
);
await
gesture
.
moveTo
(
cupertinoSwitch
);
addTearDown
(
gesture
.
removePointer
);
await
tester
.
pumpAndSettle
();
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
kIsWeb
?
SystemMouseCursors
.
click
:
SystemMouseCursors
.
basic
,
);
});
}
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