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
9f20bd6c
Unverified
Commit
9f20bd6c
authored
Jan 29, 2019
by
jslavitz
Committed by
GitHub
Jan 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds haptic vibration to Cupertino switch (#27114)
* adds haptic vibration to switch
parent
237fc2fb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
0 deletions
+52
-0
switch.dart
packages/flutter/lib/src/cupertino/switch.dart
+9
-0
switch_test.dart
packages/flutter/test/cupertino/switch_test.dart
+43
-0
No files found.
packages/flutter/lib/src/cupertino/switch.dart
View file @
9f20bd6c
...
...
@@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart';
import
'package:flutter/gestures.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/services.dart'
;
import
'colors.dart'
;
import
'thumb_painter.dart'
;
...
...
@@ -296,6 +297,14 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox {
markNeedsPaint
();
markNeedsSemanticsUpdate
();
}
switch
(
defaultTargetPlatform
)
{
case
TargetPlatform
.
iOS
:
HapticFeedback
.
lightImpact
();
break
;
case
TargetPlatform
.
fuchsia
:
case
TargetPlatform
.
android
:
break
;
}
}
TextDirection
get
textDirection
=>
_textDirection
;
...
...
packages/flutter/test/cupertino/switch_test.dart
View file @
9f20bd6c
...
...
@@ -5,6 +5,8 @@
import
'package:flutter/cupertino.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/foundation.dart'
;
void
main
(
)
{
testWidgets
(
'Switch can toggle on tap'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -37,6 +39,47 @@ void main() {
expect
(
value
,
isTrue
);
});
testWidgets
(
'Switch emits light haptic vibration on tap'
,
(
WidgetTester
tester
)
async
{
debugDefaultTargetPlatformOverride
=
TargetPlatform
.
iOS
;
final
Key
switchKey
=
UniqueKey
();
bool
value
=
false
;
final
List
<
MethodCall
>
log
=
<
MethodCall
>[];
SystemChannels
.
platform
.
setMockMethodCallHandler
((
MethodCall
methodCall
)
async
{
log
.
add
(
methodCall
);
});
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
Center
(
child:
CupertinoSwitch
(
key:
switchKey
,
value:
value
,
dragStartBehavior:
DragStartBehavior
.
down
,
onChanged:
(
bool
newValue
)
{
setState
(()
{
value
=
newValue
;
});
},
),
);
},
),
),
);
await
tester
.
tap
(
find
.
byKey
(
switchKey
));
await
tester
.
pumpAndSettle
();
expect
(
log
,
hasLength
(
1
));
expect
(
log
.
single
,
isMethodCall
(
'HapticFeedback.vibrate'
,
arguments:
'HapticFeedbackType.lightImpact'
));
debugDefaultTargetPlatformOverride
=
null
;
});
testWidgets
(
'Switch can drag (LTR)'
,
(
WidgetTester
tester
)
async
{
bool
value
=
false
;
...
...
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