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
09c80aa4
Unverified
Commit
09c80aa4
authored
Nov 08, 2019
by
LongCatIsLooong
Committed by
GitHub
Nov 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Segmented control quick double tap fix (#44391)
parent
d961ae85
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
7 deletions
+48
-7
nav_bar.dart
packages/flutter/lib/src/cupertino/nav_bar.dart
+2
-1
segmented_control.dart
packages/flutter/lib/src/cupertino/segmented_control.dart
+5
-6
segmented_control_test.dart
packages/flutter/test/cupertino/segmented_control_test.dart
+41
-0
No files found.
packages/flutter/lib/src/cupertino/nav_bar.dart
View file @
09c80aa4
...
...
@@ -289,7 +289,8 @@ class CupertinoNavigationBar extends StatefulWidget implements ObstructingPrefer
/// {@endtemplate}
final
Widget
trailing
;
// TODO(xster): implement support for double row navigation bars.
// TODO(xster): https://github.com/flutter/flutter/issues/10469 implement
// support for double row navigation bars.
/// {@template flutter.cupertino.navBar.backgroundColor}
/// The background color of the navigation bar. If it contains transparency, the
...
...
packages/flutter/lib/src/cupertino/segmented_control.dart
View file @
09c80aa4
...
...
@@ -331,10 +331,12 @@ class _SegmentedControlState<T> extends State<CupertinoSegmentedControl<T>>
}
void
_onTap
(
T
currentKey
)
{
if
(
currentKey
!=
widget
.
groupValue
&&
currentKey
==
_pressedKey
)
{
if
(
currentKey
!=
_pressedKey
)
return
;
if
(
currentKey
!=
widget
.
groupValue
)
{
widget
.
onValueChanged
(
currentKey
);
_pressedKey
=
null
;
}
_pressedKey
=
null
;
}
Color
getTextColor
(
int
index
,
T
currentKey
)
{
...
...
@@ -472,7 +474,6 @@ class _RenderSegmentedControl<T> extends RenderBox
with
ContainerRenderObjectMixin
<
RenderBox
,
ContainerBoxParentData
<
RenderBox
>>,
RenderBoxContainerDefaultsMixin
<
RenderBox
,
ContainerBoxParentData
<
RenderBox
>>
{
_RenderSegmentedControl
({
List
<
RenderBox
>
children
,
@required
int
selectedIndex
,
@required
int
pressedIndex
,
@required
TextDirection
textDirection
,
...
...
@@ -483,9 +484,7 @@ class _RenderSegmentedControl<T> extends RenderBox
_selectedIndex
=
selectedIndex
,
_pressedIndex
=
pressedIndex
,
_backgroundColors
=
backgroundColors
,
_borderColor
=
borderColor
{
addAll
(
children
);
}
_borderColor
=
borderColor
;
int
get
selectedIndex
=>
_selectedIndex
;
int
_selectedIndex
;
...
...
packages/flutter/test/cupertino/segmented_control_test.dart
View file @
09c80aa4
...
...
@@ -1384,6 +1384,47 @@ void main() {
expect
(
getBackgroundColor
(
tester
,
1
),
isSameColorAs
(
CupertinoColors
.
white
));
});
// Regression test: https://github.com/flutter/flutter/issues/43414.
testWidgets
(
"Quick double tap doesn't break the internal state"
,
(
WidgetTester
tester
)
async
{
const
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{
0
:
Text
(
'A'
),
1
:
Text
(
'B'
),
2
:
Text
(
'C'
),
};
int
sharedValue
=
0
;
await
tester
.
pumpWidget
(
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
boilerplate
(
child:
CupertinoSegmentedControl
<
int
>(
key:
const
ValueKey
<
String
>(
'Segmented Control'
),
children:
children
,
onValueChanged:
(
int
newValue
)
{
setState
(()
{
sharedValue
=
newValue
;
});
},
groupValue:
sharedValue
,
),
);
},
),
);
await
tester
.
tap
(
find
.
text
(
'B'
));
// sharedValue has been updated but widget.groupValue is not.
expect
(
sharedValue
,
1
);
// Land the second tap before the widget gets a chance to rebuild.
final
TestGesture
secondTap
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
text
(
'B'
)));
await
tester
.
pump
();
await
secondTap
.
up
();
expect
(
sharedValue
,
1
);
await
tester
.
tap
(
find
.
text
(
'C'
));
expect
(
sharedValue
,
2
);
});
testWidgets
(
'Golden Test Placeholder Widget'
,
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
Container
();
...
...
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