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
60d2735e
Commit
60d2735e
authored
Jun 16, 2019
by
Van Looveren Koen
Committed by
LongCatIsLooong
Jun 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added customizable padding for the segmented controll (#34555)
parent
a96c8e50
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
3 deletions
+96
-3
segmented_control.dart
packages/flutter/lib/src/cupertino/segmented_control.dart
+9
-3
segmented_control_test.dart
packages/flutter/test/cupertino/segmented_control_test.dart
+87
-0
No files found.
packages/flutter/lib/src/cupertino/segmented_control.dart
View file @
60d2735e
...
...
@@ -11,9 +11,9 @@ import 'package:flutter/widgets.dart';
import
'theme.dart'
;
// Minimum padding from
horizontal edges of
segmented control to edges of
// Minimum padding from
edges of the
segmented control to edges of
// encompassing widget.
const
EdgeInsets
_kHorizontalItemPadding
=
EdgeInsets
.
symmetric
(
horizontal:
16.0
);
const
EdgeInsets
Geometry
_kHorizontalItemPadding
=
EdgeInsets
.
symmetric
(
horizontal:
16.0
);
// Minimum height of the segmented control.
const
double
_kMinSegmentedControlHeight
=
28.0
;
...
...
@@ -87,6 +87,7 @@ class CupertinoSegmentedControl<T> extends StatefulWidget {
this
.
selectedColor
,
this
.
borderColor
,
this
.
pressedColor
,
this
.
padding
,
})
:
assert
(
children
!=
null
),
assert
(
children
.
length
>=
2
),
assert
(
onValueChanged
!=
null
),
...
...
@@ -179,6 +180,11 @@ class CupertinoSegmentedControl<T> extends StatefulWidget {
/// Defaults to the selectedColor at 20% opacity if null.
final
Color
pressedColor
;
/// The CupertinoSegmentedControl will be placed inside this padding
///
/// Defaults to EdgeInsets.symmetric(horizontal: 16.0)
final
EdgeInsetsGeometry
padding
;
@override
_SegmentedControlState
<
T
>
createState
()
=>
_SegmentedControlState
<
T
>();
}
...
...
@@ -407,7 +413,7 @@ class _SegmentedControlState<T> extends State<CupertinoSegmentedControl<T>>
);
return
Padding
(
padding:
_kHorizontalItemPadding
.
resolve
(
Directionality
.
of
(
context
))
,
padding:
widget
.
padding
??
_kHorizontalItemPadding
,
child:
UnconstrainedBox
(
constrainedAxis:
Axis
.
horizontal
,
child:
box
,
...
...
packages/flutter/test/cupertino/segmented_control_test.dart
View file @
60d2735e
...
...
@@ -117,6 +117,93 @@ void main() {
}
});
testWidgets
(
'Padding works'
,
(
WidgetTester
tester
)
async
{
const
Key
key
=
Key
(
'Container'
);
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
const
SizedBox
(
height:
double
.
infinity
,
child:
Text
(
'Child 1'
),
)
;
children
[
1
]
=
const
SizedBox
(
height:
double
.
infinity
,
child:
Text
(
'Child 2'
),
)
;
Future
<
void
>
verifyPadding
({
EdgeInsets
padding
})
async
{
final
EdgeInsets
effectivePadding
=
padding
??
const
EdgeInsets
.
symmetric
(
horizontal:
16
);
final
Rect
segmentedControlRect
=
tester
.
getRect
(
find
.
byKey
(
key
));
expect
(
tester
.
getTopLeft
(
find
.
byWidget
(
children
[
0
])),
segmentedControlRect
.
topLeft
.
translate
(
effectivePadding
.
topLeft
.
dx
,
effectivePadding
.
topLeft
.
dy
,
)
);
expect
(
tester
.
getBottomLeft
(
find
.
byWidget
(
children
[
0
])),
segmentedControlRect
.
bottomLeft
.
translate
(
effectivePadding
.
bottomLeft
.
dx
,
effectivePadding
.
bottomLeft
.
dy
,
),
);
expect
(
tester
.
getTopRight
(
find
.
byWidget
(
children
[
1
])),
segmentedControlRect
.
topRight
.
translate
(
effectivePadding
.
topRight
.
dx
,
effectivePadding
.
topRight
.
dy
,
),
);
expect
(
tester
.
getBottomRight
(
find
.
byWidget
(
children
[
1
])),
segmentedControlRect
.
bottomRight
.
translate
(
effectivePadding
.
bottomRight
.
dx
,
effectivePadding
.
bottomRight
.
dy
,
),
);
}
await
tester
.
pumpWidget
(
boilerplate
(
child:
CupertinoSegmentedControl
<
int
>(
key:
key
,
children:
children
,
onValueChanged:
(
int
newValue
)
{
},
),
)
);
// Default padding works.
await
verifyPadding
();
// Switch to Child 2 padding should remain the same.
await
tester
.
tap
(
find
.
text
(
'Child 2'
));
await
tester
.
pumpAndSettle
();
await
verifyPadding
();
await
tester
.
pumpWidget
(
boilerplate
(
child:
CupertinoSegmentedControl
<
int
>(
key:
key
,
padding:
const
EdgeInsets
.
fromLTRB
(
1
,
3
,
5
,
7
),
children:
children
,
onValueChanged:
(
int
newValue
)
{
},
),
)
);
// Custom padding works.
await
verifyPadding
(
padding:
const
EdgeInsets
.
fromLTRB
(
1
,
3
,
5
,
7
));
// Switch back to Child 1 padding should remain the same.
await
tester
.
tap
(
find
.
text
(
'Child 1'
));
await
tester
.
pumpAndSettle
();
await
verifyPadding
(
padding:
const
EdgeInsets
.
fromLTRB
(
1
,
3
,
5
,
7
));
});
testWidgets
(
'Value attribute must be the key of one of the children widgets'
,
(
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