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
506cf3cb
Unverified
Commit
506cf3cb
authored
Aug 01, 2018
by
Natalie Sampsell
Committed by
GitHub
Aug 01, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ability to use custom colors for SegmentedControl (#20005)
parent
091da9c7
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
177 additions
and
39 deletions
+177
-39
segmented_control.dart
packages/flutter/lib/src/cupertino/segmented_control.dart
+100
-38
segmented_control_test.dart
packages/flutter/test/cupertino/segmented_control_test.dart
+77
-1
No files found.
packages/flutter/lib/src/cupertino/segmented_control.dart
View file @
506cf3cb
This diff is collapsed.
Click to expand it.
packages/flutter/test/cupertino/segmented_control_test.dart
View file @
506cf3cb
...
...
@@ -142,7 +142,8 @@ void main() {
}
});
testWidgets
(
'Children and onValueChanged can not be null'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Children, onValueChanged, and color arguments can not be null'
,
(
WidgetTester
tester
)
async
{
try
{
await
tester
.
pumpWidget
(
boilerplate
(
...
...
@@ -174,6 +175,21 @@ void main() {
}
on
AssertionError
catch
(
e
)
{
expect
(
e
.
toString
(),
contains
(
'onValueChanged'
));
}
try
{
await
tester
.
pumpWidget
(
boilerplate
(
child:
new
SegmentedControl
<
int
>(
children:
children
,
onValueChanged:
(
int
newValue
)
{},
unselectedColor:
null
,
),
),
);
fail
(
'Should not be possible to create segmented control with null unselectedColor'
);
}
on
AssertionError
catch
(
e
)
{
expect
(
e
.
toString
(),
contains
(
'unselectedColor'
));
}
});
testWidgets
(
'Widgets have correct default text/icon styles, change correctly on selection'
,
...
...
@@ -220,6 +236,66 @@ void main() {
expect
(
iconTheme
.
data
.
color
,
CupertinoColors
.
white
);
});
testWidgets
(
'SegmentedControl is correct when user provides custom colors'
,
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
const
Text
(
'Child 1'
);
children
[
1
]
=
const
Icon
(
IconData
(
1
));
int
sharedValue
=
0
;
await
tester
.
pumpWidget
(
new
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
boilerplate
(
child:
new
SegmentedControl
<
int
>(
children:
children
,
onValueChanged:
(
int
newValue
)
{
setState
(()
{
sharedValue
=
newValue
;
});
},
groupValue:
sharedValue
,
unselectedColor:
CupertinoColors
.
lightBackgroundGray
,
selectedColor:
CupertinoColors
.
activeGreen
,
borderColor:
CupertinoColors
.
black
,
pressedColor:
const
Color
(
0x638CFC7B
),
),
);
},
),
);
await
tester
.
pumpAndSettle
();
DefaultTextStyle
textStyle
=
tester
.
widget
(
find
.
widgetWithText
(
DefaultTextStyle
,
'Child 1'
));
IconTheme
iconTheme
=
tester
.
widget
(
find
.
widgetWithIcon
(
IconTheme
,
const
IconData
(
1
)));
expect
(
getRenderSegmentedControl
(
tester
).
borderColor
,
CupertinoColors
.
black
);
expect
(
textStyle
.
style
.
color
,
CupertinoColors
.
lightBackgroundGray
);
expect
(
iconTheme
.
data
.
color
,
CupertinoColors
.
activeGreen
);
expect
(
getBackgroundColor
(
tester
,
0
),
CupertinoColors
.
activeGreen
);
expect
(
getBackgroundColor
(
tester
,
1
),
CupertinoColors
.
lightBackgroundGray
);
await
tester
.
tap
(
find
.
widgetWithIcon
(
IconTheme
,
const
IconData
(
1
)));
await
tester
.
pumpAndSettle
();
textStyle
=
tester
.
widget
(
find
.
widgetWithText
(
DefaultTextStyle
,
'Child 1'
));
iconTheme
=
tester
.
widget
(
find
.
widgetWithIcon
(
IconTheme
,
const
IconData
(
1
)));
expect
(
textStyle
.
style
.
color
,
CupertinoColors
.
activeGreen
);
expect
(
iconTheme
.
data
.
color
,
CupertinoColors
.
lightBackgroundGray
);
expect
(
getBackgroundColor
(
tester
,
0
),
CupertinoColors
.
lightBackgroundGray
);
expect
(
getBackgroundColor
(
tester
,
1
),
CupertinoColors
.
activeGreen
);
final
Offset
center
=
tester
.
getCenter
(
find
.
text
(
'Child 1'
));
await
tester
.
startGesture
(
center
);
await
tester
.
pumpAndSettle
();
expect
(
getBackgroundColor
(
tester
,
0
),
const
Color
(
0x638CFC7B
));
expect
(
getBackgroundColor
(
tester
,
1
),
CupertinoColors
.
activeGreen
);
});
testWidgets
(
'Tap calls onValueChanged'
,
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
const
Text
(
'Child 1'
);
...
...
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