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
4ef02927
Commit
4ef02927
authored
Apr 16, 2019
by
Tom Robiquet
Committed by
xster
Apr 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added opacity to cupertino switch when disabled (#29451)
parent
4dd15253
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
7 deletions
+110
-7
switch.dart
packages/flutter/lib/src/cupertino/switch.dart
+12
-7
switch_test.dart
packages/flutter/test/cupertino/switch_test.dart
+98
-0
No files found.
packages/flutter/lib/src/cupertino/switch.dart
View file @
4ef02927
...
...
@@ -77,7 +77,7 @@ class CupertinoSwitch extends StatefulWidget {
/// change state until the parent widget rebuilds the switch with the new
/// value.
///
/// If null, the switch will be displayed as disabled.
/// If null, the switch will be displayed as disabled
, which has a reduced opacity
.
///
/// The callback provided to onChanged should update the state of the parent
/// [StatefulWidget] using the [State.setState] method, so that the parent
...
...
@@ -135,12 +135,15 @@ class CupertinoSwitch extends StatefulWidget {
class
_CupertinoSwitchState
extends
State
<
CupertinoSwitch
>
with
TickerProviderStateMixin
{
@override
Widget
build
(
BuildContext
context
)
{
return
_CupertinoSwitchRenderObjectWidget
(
value:
widget
.
value
,
activeColor:
widget
.
activeColor
??
CupertinoColors
.
activeGreen
,
onChanged:
widget
.
onChanged
,
vsync:
this
,
dragStartBehavior:
widget
.
dragStartBehavior
,
return
Opacity
(
opacity:
widget
.
onChanged
==
null
?
_kCupertinoSwitchDisabledOpacity
:
1.0
,
child:
_CupertinoSwitchRenderObjectWidget
(
value:
widget
.
value
,
activeColor:
widget
.
activeColor
??
CupertinoColors
.
activeGreen
,
onChanged:
widget
.
onChanged
,
vsync:
this
,
dragStartBehavior:
widget
.
dragStartBehavior
,
),
);
}
}
...
...
@@ -193,6 +196,8 @@ const double _kTrackInnerEnd = _kTrackWidth - _kTrackInnerStart;
const
double
_kTrackInnerLength
=
_kTrackInnerEnd
-
_kTrackInnerStart
;
const
double
_kSwitchWidth
=
59.0
;
const
double
_kSwitchHeight
=
39.0
;
// Opacity of a disabled switch, as eye-balled from iOS Simulator on Mac.
const
double
_kCupertinoSwitchDisabledOpacity
=
0.5
;
const
Color
_kTrackColor
=
CupertinoColors
.
lightBackgroundGray
;
const
Duration
_kReactionDuration
=
Duration
(
milliseconds:
300
);
...
...
packages/flutter/test/cupertino/switch_test.dart
View file @
4ef02927
...
...
@@ -415,4 +415,102 @@ void main() {
expect
(
value
,
isFalse
);
});
testWidgets
(
'Switch is translucent when disabled'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
CupertinoSwitch
(
value:
false
,
dragStartBehavior:
DragStartBehavior
.
down
,
onChanged:
null
,
),
)
),
);
expect
(
find
.
byType
(
Opacity
),
findsOneWidget
);
expect
(
tester
.
widget
<
Opacity
>(
find
.
byType
(
Opacity
).
first
).
opacity
,
0.5
);
});
testWidgets
(
'Switch is opaque when enabled'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
CupertinoSwitch
(
value:
false
,
dragStartBehavior:
DragStartBehavior
.
down
,
onChanged:
(
bool
newValue
)
{},
),
)
),
);
expect
(
find
.
byType
(
Opacity
),
findsOneWidget
);
expect
(
tester
.
widget
<
Opacity
>(
find
.
byType
(
Opacity
).
first
).
opacity
,
1.0
);
});
testWidgets
(
'Switch turns translucent after becoming disabled'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
CupertinoSwitch
(
value:
false
,
dragStartBehavior:
DragStartBehavior
.
down
,
onChanged:
(
bool
newValue
)
{},
),
)
),
);
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
CupertinoSwitch
(
value:
false
,
dragStartBehavior:
DragStartBehavior
.
down
,
onChanged:
null
,
),
)
),
);
expect
(
find
.
byType
(
Opacity
),
findsOneWidget
);
expect
(
tester
.
widget
<
Opacity
>(
find
.
byType
(
Opacity
).
first
).
opacity
,
0.5
);
});
testWidgets
(
'Switch turns opaque after becoming enabled'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
CupertinoSwitch
(
value:
false
,
dragStartBehavior:
DragStartBehavior
.
down
,
onChanged:
null
,
),
)
),
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
CupertinoSwitch
(
value:
false
,
dragStartBehavior:
DragStartBehavior
.
down
,
onChanged:
(
bool
newValue
)
{},
),
)
),
);
expect
(
find
.
byType
(
Opacity
),
findsOneWidget
);
expect
(
tester
.
widget
<
Opacity
>(
find
.
byType
(
Opacity
).
first
).
opacity
,
1.0
);
});
}
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