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
e08538c3
Commit
e08538c3
authored
Jul 24, 2019
by
brandondiamond
Committed by
Justin McCandless
Jul 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update visual style of CupertinoSwitch to match iOS 13 (#36087)
parent
dfc636bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
11 deletions
+71
-11
switch.dart
packages/flutter/lib/src/cupertino/switch.dart
+9
-11
switch_test.dart
packages/flutter/test/cupertino/switch_test.dart
+62
-0
No files found.
packages/flutter/lib/src/cupertino/switch.dart
View file @
e08538c3
...
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:math'
as
math
;
import
'dart:ui'
show
lerpDouble
;
import
'package:flutter/foundation.dart'
;
...
...
@@ -478,11 +477,8 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox {
break
;
}
final
Color
trackColor
=
_value
?
activeColor
:
_kTrackColor
;
final
double
borderThickness
=
1.5
+
(
_kTrackRadius
-
1.5
)
*
math
.
max
(
currentReactionValue
,
currentValue
);
final
Paint
paint
=
Paint
()
..
color
=
trackColor
;
..
color
=
Color
.
lerp
(
_kTrackColor
,
activeColor
,
currentValue
)
;
final
Rect
trackRect
=
Rect
.
fromLTWH
(
offset
.
dx
+
(
size
.
width
-
_kTrackWidth
)
/
2.0
,
...
...
@@ -490,9 +486,8 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox {
_kTrackWidth
,
_kTrackHeight
,
);
final
RRect
outerRRect
=
RRect
.
fromRectAndRadius
(
trackRect
,
const
Radius
.
circular
(
_kTrackRadius
));
final
RRect
innerRRect
=
RRect
.
fromRectAndRadius
(
trackRect
.
deflate
(
borderThickness
),
const
Radius
.
circular
(
_kTrackRadius
));
canvas
.
drawDRRect
(
outerRRect
,
innerRRect
,
paint
);
final
RRect
trackRRect
=
RRect
.
fromRectAndRadius
(
trackRect
,
const
Radius
.
circular
(
_kTrackRadius
));
canvas
.
drawRRect
(
trackRRect
,
paint
);
final
double
currentThumbExtension
=
CupertinoThumbPainter
.
extension
*
currentReactionValue
;
final
double
thumbLeft
=
lerpDouble
(
...
...
@@ -506,13 +501,16 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox {
visualPosition
,
);
final
double
thumbCenterY
=
offset
.
dy
+
size
.
height
/
2.0
;
_thumbPainter
.
paint
(
canvas
,
Rect
.
fromLTRB
(
final
Rect
thumbBounds
=
Rect
.
fromLTRB
(
thumbLeft
,
thumbCenterY
-
CupertinoThumbPainter
.
radius
,
thumbRight
,
thumbCenterY
+
CupertinoThumbPainter
.
radius
,
));
);
context
.
pushClipRRect
(
needsCompositing
,
Offset
.
zero
,
thumbBounds
,
trackRRect
,
(
PaintingContext
innerContext
,
Offset
offset
)
{
_thumbPainter
.
paint
(
innerContext
.
canvas
,
thumbBounds
);
});
}
@override
...
...
packages/flutter/test/cupertino/switch_test.dart
View file @
e08538c3
...
...
@@ -513,4 +513,66 @@ void main() {
expect
(
tester
.
widget
<
Opacity
>(
find
.
byType
(
Opacity
).
first
).
opacity
,
1.0
);
});
testWidgets
(
'Switch renders correctly before, during, and after being tapped'
,
(
WidgetTester
tester
)
async
{
final
Key
switchKey
=
UniqueKey
();
bool
value
=
false
;
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
Center
(
child:
RepaintBoundary
(
child:
CupertinoSwitch
(
key:
switchKey
,
value:
value
,
dragStartBehavior:
DragStartBehavior
.
down
,
onChanged:
(
bool
newValue
)
{
setState
(()
{
value
=
newValue
;
});
},
)
)
);
},
),
),
);
await
expectLater
(
find
.
byKey
(
switchKey
),
matchesGoldenFile
(
'switch.tap.off.png'
,
version:
0
,
),
skip:
!
isLinux
,
);
await
tester
.
tap
(
find
.
byKey
(
switchKey
));
expect
(
value
,
isTrue
);
// Kick off animation, then advance to intermediate frame.
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
milliseconds:
60
));
await
expectLater
(
find
.
byKey
(
switchKey
),
matchesGoldenFile
(
'switch.tap.turningOn.png'
,
version:
0
,
),
skip:
!
isLinux
,
);
await
tester
.
pumpAndSettle
();
await
expectLater
(
find
.
byKey
(
switchKey
),
matchesGoldenFile
(
'switch.tap.on.png'
,
version:
0
,
),
skip:
!
isLinux
,
);
});
}
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