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
844a8ad7
Unverified
Commit
844a8ad7
authored
Sep 21, 2022
by
Taha Tesser
Committed by
GitHub
Sep 21, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update `CupertinoSwitch` example (#112063)
parent
cf01ecd1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
41 deletions
+11
-41
cupertino_switch.0.dart
examples/api/lib/cupertino/switch/cupertino_switch.0.dart
+11
-33
cupertino_switch.0_test.dart
...es/api/test/cupertino/switch/cupertino_switch.0_test.dart
+0
-8
No files found.
examples/api/lib/cupertino/switch/cupertino_switch.0.dart
View file @
844a8ad7
...
@@ -28,7 +28,7 @@ class CupertinoSwitchExample extends StatefulWidget {
...
@@ -28,7 +28,7 @@ class CupertinoSwitchExample extends StatefulWidget {
}
}
class
_CupertinoSwitchExampleState
extends
State
<
CupertinoSwitchExample
>
{
class
_CupertinoSwitchExampleState
extends
State
<
CupertinoSwitchExample
>
{
bool
wifi
=
true
;
bool
switchValue
=
true
;
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
...
@@ -37,38 +37,16 @@ class _CupertinoSwitchExampleState extends State<CupertinoSwitchExample> {
...
@@ -37,38 +37,16 @@ class _CupertinoSwitchExampleState extends State<CupertinoSwitchExample> {
middle:
Text
(
'CupertinoSwitch Sample'
),
middle:
Text
(
'CupertinoSwitch Sample'
),
),
),
child:
Center
(
child:
Center
(
// CupertinoFormRow's main axis is set to max by default.
child:
CupertinoSwitch
(
// Set the intrinsic height widget to center the CupertinoFormRow.
// This bool value toggles the switch.
child:
IntrinsicHeight
(
value:
switchValue
,
child:
Container
(
activeColor:
CupertinoColors
.
activeBlue
,
color:
CupertinoTheme
.
of
(
context
).
barBackgroundColor
,
onChanged:
(
bool
?
value
)
{
child:
CupertinoFormRow
(
// This is called when the user toggles the switch.
prefix:
Row
(
setState
(()
{
children:
<
Widget
>[
switchValue
=
value
??
false
;
Icon
(
});
// Wifi icon is updated based on switch value.
},
wifi
?
CupertinoIcons
.
wifi
:
CupertinoIcons
.
wifi_slash
,
color:
wifi
?
CupertinoColors
.
systemBlue
:
CupertinoColors
.
systemRed
,
),
const
SizedBox
(
width:
10
),
const
Text
(
'Wi-Fi'
)
],
),
child:
CupertinoSwitch
(
// This bool value toggles the switch.
value:
wifi
,
thumbColor:
CupertinoColors
.
systemBlue
,
trackColor:
CupertinoColors
.
systemRed
.
withOpacity
(
0.14
),
activeColor:
CupertinoColors
.
systemRed
.
withOpacity
(
0.64
),
onChanged:
(
bool
?
value
)
{
// This is called when the user toggles the switch.
setState
(()
{
wifi
=
value
!;
});
},
),
),
),
),
),
),
),
);
);
...
...
examples/api/test/cupertino/switch/cupertino_switch.0_test.dart
View file @
844a8ad7
...
@@ -14,19 +14,11 @@ void main() {
...
@@ -14,19 +14,11 @@ void main() {
final
Finder
switchFinder
=
find
.
byType
(
CupertinoSwitch
);
final
Finder
switchFinder
=
find
.
byType
(
CupertinoSwitch
);
CupertinoSwitch
cupertinoSwitch
=
tester
.
widget
<
CupertinoSwitch
>(
switchFinder
);
CupertinoSwitch
cupertinoSwitch
=
tester
.
widget
<
CupertinoSwitch
>(
switchFinder
);
final
Finder
wifiOnIcon
=
find
.
byIcon
(
CupertinoIcons
.
wifi
);
final
Finder
wifiOffIcon
=
find
.
byIcon
(
CupertinoIcons
.
wifi_slash
);
expect
(
cupertinoSwitch
.
value
,
true
);
expect
(
cupertinoSwitch
.
value
,
true
);
// When the switch is on, wifi icon should be visible.
expect
(
wifiOnIcon
,
findsOneWidget
);
expect
(
wifiOffIcon
,
findsNothing
);
await
tester
.
tap
(
switchFinder
);
await
tester
.
tap
(
switchFinder
);
await
tester
.
pumpAndSettle
();
await
tester
.
pumpAndSettle
();
cupertinoSwitch
=
tester
.
widget
<
CupertinoSwitch
>(
switchFinder
);
cupertinoSwitch
=
tester
.
widget
<
CupertinoSwitch
>(
switchFinder
);
expect
(
cupertinoSwitch
.
value
,
false
);
expect
(
cupertinoSwitch
.
value
,
false
);
// When the switch is off, wifi slash icon should be visible.
expect
(
wifiOnIcon
,
findsNothing
);
expect
(
wifiOffIcon
,
findsOneWidget
);
});
});
}
}
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