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
417db34d
Commit
417db34d
authored
Dec 04, 2019
by
Sebastian Döll
Committed by
LongCatIsLooong
Dec 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set track color in Cupertino Switch and Adaptive Switch (#45074)
parent
50532f38
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
2 deletions
+42
-2
switch.dart
packages/flutter/lib/src/cupertino/switch.dart
+11
-2
switch.dart
packages/flutter/lib/src/material/switch.dart
+1
-0
switch_test.dart
packages/flutter/test/cupertino/switch_test.dart
+25
-0
switch_test.dart
packages/flutter/test/material/switch_test.dart
+5
-0
No files found.
packages/flutter/lib/src/cupertino/switch.dart
View file @
417db34d
...
...
@@ -60,6 +60,7 @@ class CupertinoSwitch extends StatefulWidget {
@required
this
.
value
,
@required
this
.
onChanged
,
this
.
activeColor
,
this
.
trackColor
,
this
.
dragStartBehavior
=
DragStartBehavior
.
start
,
})
:
assert
(
value
!=
null
),
assert
(
dragStartBehavior
!=
null
),
...
...
@@ -100,6 +101,11 @@ class CupertinoSwitch extends StatefulWidget {
/// the [CupertinoTheme] in accordance to native iOS behavior.
final
Color
activeColor
;
/// The color to use for the background when the switch is off.
///
/// Defaults to [CupertinoColors.secondarySystemFill] when null.
final
Color
trackColor
;
/// {@template flutter.cupertino.switch.dragStartBehavior}
/// Determines the way that drag start behavior is handled.
///
...
...
@@ -144,6 +150,7 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt
widget
.
activeColor
??
CupertinoColors
.
systemGreen
,
context
,
),
trackColor:
CupertinoDynamicColor
.
resolve
(
widget
.
trackColor
??
CupertinoColors
.
secondarySystemFill
,
context
),
onChanged:
widget
.
onChanged
,
vsync:
this
,
dragStartBehavior:
widget
.
dragStartBehavior
,
...
...
@@ -157,6 +164,7 @@ class _CupertinoSwitchRenderObjectWidget extends LeafRenderObjectWidget {
Key
key
,
this
.
value
,
this
.
activeColor
,
this
.
trackColor
,
this
.
onChanged
,
this
.
vsync
,
this
.
dragStartBehavior
=
DragStartBehavior
.
start
,
...
...
@@ -164,6 +172,7 @@ class _CupertinoSwitchRenderObjectWidget extends LeafRenderObjectWidget {
final
bool
value
;
final
Color
activeColor
;
final
Color
trackColor
;
final
ValueChanged
<
bool
>
onChanged
;
final
TickerProvider
vsync
;
final
DragStartBehavior
dragStartBehavior
;
...
...
@@ -173,7 +182,7 @@ class _CupertinoSwitchRenderObjectWidget extends LeafRenderObjectWidget {
return
_RenderCupertinoSwitch
(
value:
value
,
activeColor:
activeColor
,
trackColor:
CupertinoDynamicColor
.
resolve
(
CupertinoColors
.
secondarySystemFill
,
context
)
,
trackColor:
trackColor
,
onChanged:
onChanged
,
textDirection:
Directionality
.
of
(
context
),
vsync:
vsync
,
...
...
@@ -186,7 +195,7 @@ class _CupertinoSwitchRenderObjectWidget extends LeafRenderObjectWidget {
renderObject
..
value
=
value
..
activeColor
=
activeColor
..
trackColor
=
CupertinoDynamicColor
.
resolve
(
CupertinoColors
.
secondarySystemFill
,
context
)
..
trackColor
=
trackColor
..
onChanged
=
onChanged
..
textDirection
=
Directionality
.
of
(
context
)
..
vsync
=
vsync
...
...
packages/flutter/lib/src/material/switch.dart
View file @
417db34d
...
...
@@ -335,6 +335,7 @@ class _SwitchState extends State<Switch> with TickerProviderStateMixin {
value:
widget
.
value
,
onChanged:
widget
.
onChanged
,
activeColor:
widget
.
activeColor
,
trackColor:
widget
.
inactiveTrackColor
),
),
);
...
...
packages/flutter/test/cupertino/switch_test.dart
View file @
417db34d
...
...
@@ -7,6 +7,9 @@ import 'package:flutter_test/flutter_test.dart';
import
'package:flutter/gestures.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'../rendering/mock_canvas.dart'
;
void
main
(
)
{
testWidgets
(
'Switch can toggle on tap'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -433,6 +436,28 @@ void main() {
expect
(
tester
.
widget
<
Opacity
>(
find
.
byType
(
Opacity
).
first
).
opacity
,
0.5
);
});
testWidgets
(
'Switch is using track color when set'
,
(
WidgetTester
tester
)
async
{
const
Color
trackColor
=
Color
(
0xFF00FF00
);
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
CupertinoSwitch
(
value:
false
,
trackColor:
trackColor
,
dragStartBehavior:
DragStartBehavior
.
down
,
onChanged:
null
,
),
),
),
);
expect
(
find
.
byType
(
CupertinoSwitch
),
findsOneWidget
);
expect
(
tester
.
widget
<
CupertinoSwitch
>(
find
.
byType
(
CupertinoSwitch
)).
trackColor
,
trackColor
);
expect
(
find
.
byType
(
CupertinoSwitch
),
paints
..
rrect
(
color:
trackColor
));
});
testWidgets
(
'Switch is opaque when enabled'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
...
...
packages/flutter/test/material/switch_test.dart
View file @
417db34d
...
...
@@ -585,6 +585,7 @@ void main() {
testWidgets
(
'Switch.adaptive'
,
(
WidgetTester
tester
)
async
{
bool
value
=
false
;
const
Color
inactiveTrackColor
=
Colors
.
pink
;
Widget
buildFrame
(
TargetPlatform
platform
)
{
return
MaterialApp
(
...
...
@@ -595,6 +596,7 @@ void main() {
child:
Center
(
child:
Switch
.
adaptive
(
value:
value
,
inactiveTrackColor:
inactiveTrackColor
,
onChanged:
(
bool
newValue
)
{
setState
(()
{
value
=
newValue
;
...
...
@@ -611,6 +613,9 @@ void main() {
await
tester
.
pumpWidget
(
buildFrame
(
TargetPlatform
.
iOS
));
expect
(
find
.
byType
(
CupertinoSwitch
),
findsOneWidget
);
final
CupertinoSwitch
adaptiveSwitch
=
tester
.
widget
(
find
.
byType
(
CupertinoSwitch
));
expect
(
adaptiveSwitch
.
trackColor
,
inactiveTrackColor
);
expect
(
value
,
isFalse
);
await
tester
.
tap
(
find
.
byType
(
Switch
));
expect
(
value
,
isTrue
);
...
...
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