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
f7b2722d
Unverified
Commit
f7b2722d
authored
Aug 31, 2018
by
liyuqian
Committed by
GitHub
Aug 31, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add clipBehavior to Chips and update documents (#21231)
This fixes
https://github.com/flutter/flutter/issues/20746
parent
cda2c223
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
11 deletions
+95
-11
chip.dart
packages/flutter/lib/src/material/chip.dart
+43
-10
chip_theme.dart
packages/flutter/lib/src/material/chip_theme.dart
+1
-1
chip_test.dart
packages/flutter/test/material/chip_test.dart
+51
-0
No files found.
packages/flutter/lib/src/material/chip.dart
View file @
f7b2722d
...
@@ -85,12 +85,15 @@ abstract class ChipAttributes {
...
@@ -85,12 +85,15 @@ abstract class ChipAttributes {
/// Defaults to the shape in the ambient [ChipThemeData].
/// Defaults to the shape in the ambient [ChipThemeData].
ShapeBorder
get
shape
;
ShapeBorder
get
shape
;
/// {@macro flutter.widgets.Clip}
Clip
get
clipBehavior
;
/// Color to be used for the unselected, enabled chip's background.
/// Color to be used for the unselected, enabled chip's background.
///
///
/// The default is light grey.
/// The default is light grey.
Color
get
backgroundColor
;
Color
get
backgroundColor
;
/// The padding between the contents of the chip and the outside [
border
].
/// The padding between the contents of the chip and the outside [
shape
].
///
///
/// Defaults to 4 logical pixels on all sides.
/// Defaults to 4 logical pixels on all sides.
EdgeInsetsGeometry
get
padding
;
EdgeInsetsGeometry
get
padding
;
...
@@ -388,8 +391,8 @@ abstract class TappableChipAttributes {
...
@@ -388,8 +391,8 @@ abstract class TappableChipAttributes {
/// Supplying a non-null [onDeleted] callback will cause the chip to include a
/// Supplying a non-null [onDeleted] callback will cause the chip to include a
/// button for deleting the chip.
/// button for deleting the chip.
///
///
/// Requires one of its ancestors to be a [Material] widget. The [label]
,
/// Requires one of its ancestors to be a [Material] widget. The [label]
///
[deleteIcon], and [borde
r] arguments must not be null.
///
and [clipBehavio
r] arguments must not be null.
///
///
/// ## Sample code
/// ## Sample code
///
///
...
@@ -419,7 +422,7 @@ abstract class TappableChipAttributes {
...
@@ -419,7 +422,7 @@ abstract class TappableChipAttributes {
class
Chip
extends
StatelessWidget
implements
ChipAttributes
,
DeletableChipAttributes
{
class
Chip
extends
StatelessWidget
implements
ChipAttributes
,
DeletableChipAttributes
{
/// Creates a material design chip.
/// Creates a material design chip.
///
///
/// The [label] a
rgument
must not be null.
/// The [label] a
nd [clipBehavior] arguments
must not be null.
const
Chip
({
const
Chip
({
Key
key
,
Key
key
,
this
.
avatar
,
this
.
avatar
,
...
@@ -431,10 +434,12 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
...
@@ -431,10 +434,12 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
this
.
deleteIconColor
,
this
.
deleteIconColor
,
this
.
deleteButtonTooltipMessage
,
this
.
deleteButtonTooltipMessage
,
this
.
shape
,
this
.
shape
,
this
.
clipBehavior
=
Clip
.
none
,
this
.
backgroundColor
,
this
.
backgroundColor
,
this
.
padding
,
this
.
padding
,
this
.
materialTapTargetSize
,
this
.
materialTapTargetSize
,
})
:
assert
(
label
!=
null
),
})
:
assert
(
label
!=
null
),
assert
(
clipBehavior
!=
null
),
super
(
key:
key
);
super
(
key:
key
);
@override
@override
...
@@ -448,6 +453,8 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
...
@@ -448,6 +453,8 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
@override
@override
final
ShapeBorder
shape
;
final
ShapeBorder
shape
;
@override
@override
final
Clip
clipBehavior
;
@override
final
Color
backgroundColor
;
final
Color
backgroundColor
;
@override
@override
final
EdgeInsetsGeometry
padding
;
final
EdgeInsetsGeometry
padding
;
...
@@ -476,6 +483,7 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
...
@@ -476,6 +483,7 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
deleteButtonTooltipMessage:
deleteButtonTooltipMessage
,
deleteButtonTooltipMessage:
deleteButtonTooltipMessage
,
tapEnabled:
false
,
tapEnabled:
false
,
shape:
shape
,
shape:
shape
,
clipBehavior:
clipBehavior
,
backgroundColor:
backgroundColor
,
backgroundColor:
backgroundColor
,
padding:
padding
,
padding:
padding
,
materialTapTargetSize:
materialTapTargetSize
,
materialTapTargetSize:
materialTapTargetSize
,
...
@@ -540,7 +548,8 @@ class InputChip extends StatelessWidget
...
@@ -540,7 +548,8 @@ class InputChip extends StatelessWidget
/// The [onPressed] and [onSelected] callbacks must not both be specified at
/// The [onPressed] and [onSelected] callbacks must not both be specified at
/// the same time.
/// the same time.
///
///
/// The [label], [isEnabled] and [selected] arguments must not be null.
/// The [label], [isEnabled], [selected], and [clipBehavior] arguments must
/// not be null.
const
InputChip
({
const
InputChip
({
Key
key
,
Key
key
,
this
.
avatar
,
this
.
avatar
,
...
@@ -559,12 +568,14 @@ class InputChip extends StatelessWidget
...
@@ -559,12 +568,14 @@ class InputChip extends StatelessWidget
this
.
selectedColor
,
this
.
selectedColor
,
this
.
tooltip
,
this
.
tooltip
,
this
.
shape
,
this
.
shape
,
this
.
clipBehavior
=
Clip
.
none
,
this
.
backgroundColor
,
this
.
backgroundColor
,
this
.
padding
,
this
.
padding
,
this
.
materialTapTargetSize
,
this
.
materialTapTargetSize
,
})
:
assert
(
selected
!=
null
),
})
:
assert
(
selected
!=
null
),
assert
(
isEnabled
!=
null
),
assert
(
isEnabled
!=
null
),
assert
(
label
!=
null
),
assert
(
label
!=
null
),
assert
(
clipBehavior
!=
null
),
super
(
key:
key
);
super
(
key:
key
);
@override
@override
...
@@ -600,6 +611,8 @@ class InputChip extends StatelessWidget
...
@@ -600,6 +611,8 @@ class InputChip extends StatelessWidget
@override
@override
final
ShapeBorder
shape
;
final
ShapeBorder
shape
;
@override
@override
final
Clip
clipBehavior
;
@override
final
Color
backgroundColor
;
final
Color
backgroundColor
;
@override
@override
final
EdgeInsetsGeometry
padding
;
final
EdgeInsetsGeometry
padding
;
...
@@ -626,6 +639,7 @@ class InputChip extends StatelessWidget
...
@@ -626,6 +639,7 @@ class InputChip extends StatelessWidget
selectedColor:
selectedColor
,
selectedColor:
selectedColor
,
tooltip:
tooltip
,
tooltip:
tooltip
,
shape:
shape
,
shape:
shape
,
clipBehavior:
clipBehavior
,
backgroundColor:
backgroundColor
,
backgroundColor:
backgroundColor
,
padding:
padding
,
padding:
padding
,
materialTapTargetSize:
materialTapTargetSize
,
materialTapTargetSize:
materialTapTargetSize
,
...
@@ -639,8 +653,8 @@ class InputChip extends StatelessWidget
...
@@ -639,8 +653,8 @@ class InputChip extends StatelessWidget
/// [ChoiceChip]s represent a single choice from a set. Choice chips contain
/// [ChoiceChip]s represent a single choice from a set. Choice chips contain
/// related descriptive text or categories.
/// related descriptive text or categories.
///
///
/// Requires one of its ancestors to be a [Material] widget. The [selected]
,
/// Requires one of its ancestors to be a [Material] widget. The [selected]
and
/// [label]
, and [border]
arguments must not be null.
/// [label] arguments must not be null.
///
///
/// ## Sample code
/// ## Sample code
///
///
...
@@ -692,7 +706,7 @@ class ChoiceChip extends StatelessWidget
...
@@ -692,7 +706,7 @@ class ChoiceChip extends StatelessWidget
DisabledChipAttributes
{
DisabledChipAttributes
{
/// Create a chip that acts like a radio button.
/// Create a chip that acts like a radio button.
///
///
/// The [label]
and [selected
] attributes must not be null.
/// The [label]
, [selected], and [clipBehavior
] attributes must not be null.
const
ChoiceChip
({
const
ChoiceChip
({
Key
key
,
Key
key
,
this
.
avatar
,
this
.
avatar
,
...
@@ -705,11 +719,13 @@ class ChoiceChip extends StatelessWidget
...
@@ -705,11 +719,13 @@ class ChoiceChip extends StatelessWidget
this
.
disabledColor
,
this
.
disabledColor
,
this
.
tooltip
,
this
.
tooltip
,
this
.
shape
,
this
.
shape
,
this
.
clipBehavior
=
Clip
.
none
,
this
.
backgroundColor
,
this
.
backgroundColor
,
this
.
padding
,
this
.
padding
,
this
.
materialTapTargetSize
,
this
.
materialTapTargetSize
,
})
:
assert
(
selected
!=
null
),
})
:
assert
(
selected
!=
null
),
assert
(
label
!=
null
),
assert
(
label
!=
null
),
assert
(
clipBehavior
!=
null
),
super
(
key:
key
);
super
(
key:
key
);
@override
@override
...
@@ -733,6 +749,8 @@ class ChoiceChip extends StatelessWidget
...
@@ -733,6 +749,8 @@ class ChoiceChip extends StatelessWidget
@override
@override
final
ShapeBorder
shape
;
final
ShapeBorder
shape
;
@override
@override
final
Clip
clipBehavior
;
@override
final
Color
backgroundColor
;
final
Color
backgroundColor
;
@override
@override
final
EdgeInsetsGeometry
padding
;
final
EdgeInsetsGeometry
padding
;
...
@@ -757,6 +775,7 @@ class ChoiceChip extends StatelessWidget
...
@@ -757,6 +775,7 @@ class ChoiceChip extends StatelessWidget
onDeleted:
null
,
onDeleted:
null
,
tooltip:
tooltip
,
tooltip:
tooltip
,
shape:
shape
,
shape:
shape
,
clipBehavior:
clipBehavior
,
disabledColor:
disabledColor
,
disabledColor:
disabledColor
,
selectedColor:
selectedColor
??
chipTheme
.
secondarySelectedColor
,
selectedColor:
selectedColor
??
chipTheme
.
secondarySelectedColor
,
backgroundColor:
backgroundColor
,
backgroundColor:
backgroundColor
,
...
@@ -872,11 +891,13 @@ class FilterChip extends StatelessWidget
...
@@ -872,11 +891,13 @@ class FilterChip extends StatelessWidget
this
.
selectedColor
,
this
.
selectedColor
,
this
.
tooltip
,
this
.
tooltip
,
this
.
shape
,
this
.
shape
,
this
.
clipBehavior
=
Clip
.
none
,
this
.
backgroundColor
,
this
.
backgroundColor
,
this
.
padding
,
this
.
padding
,
this
.
materialTapTargetSize
,
this
.
materialTapTargetSize
,
})
:
assert
(
selected
!=
null
),
})
:
assert
(
selected
!=
null
),
assert
(
label
!=
null
),
assert
(
label
!=
null
),
assert
(
clipBehavior
!=
null
),
super
(
key:
key
);
super
(
key:
key
);
@override
@override
...
@@ -900,6 +921,8 @@ class FilterChip extends StatelessWidget
...
@@ -900,6 +921,8 @@ class FilterChip extends StatelessWidget
@override
@override
final
ShapeBorder
shape
;
final
ShapeBorder
shape
;
@override
@override
final
Clip
clipBehavior
;
@override
final
Color
backgroundColor
;
final
Color
backgroundColor
;
@override
@override
final
EdgeInsetsGeometry
padding
;
final
EdgeInsetsGeometry
padding
;
...
@@ -921,6 +944,7 @@ class FilterChip extends StatelessWidget
...
@@ -921,6 +944,7 @@ class FilterChip extends StatelessWidget
selected:
selected
,
selected:
selected
,
tooltip:
tooltip
,
tooltip:
tooltip
,
shape:
shape
,
shape:
shape
,
clipBehavior:
clipBehavior
,
backgroundColor:
backgroundColor
,
backgroundColor:
backgroundColor
,
disabledColor:
disabledColor
,
disabledColor:
disabledColor
,
selectedColor:
selectedColor
,
selectedColor:
selectedColor
,
...
@@ -980,7 +1004,7 @@ class FilterChip extends StatelessWidget
...
@@ -980,7 +1004,7 @@ class FilterChip extends StatelessWidget
class
ActionChip
extends
StatelessWidget
implements
ChipAttributes
,
TappableChipAttributes
{
class
ActionChip
extends
StatelessWidget
implements
ChipAttributes
,
TappableChipAttributes
{
/// Create a chip that acts like a button.
/// Create a chip that acts like a button.
///
///
/// The [label]
and [onPressed
] arguments must not be null.
/// The [label]
, [onPressed], and [clipBehavior
] arguments must not be null.
const
ActionChip
({
const
ActionChip
({
Key
key
,
Key
key
,
this
.
avatar
,
this
.
avatar
,
...
@@ -990,6 +1014,7 @@ class ActionChip extends StatelessWidget implements ChipAttributes, TappableChip
...
@@ -990,6 +1014,7 @@ class ActionChip extends StatelessWidget implements ChipAttributes, TappableChip
@required
this
.
onPressed
,
@required
this
.
onPressed
,
this
.
tooltip
,
this
.
tooltip
,
this
.
shape
,
this
.
shape
,
this
.
clipBehavior
=
Clip
.
none
,
this
.
backgroundColor
,
this
.
backgroundColor
,
this
.
padding
,
this
.
padding
,
this
.
materialTapTargetSize
,
this
.
materialTapTargetSize
,
...
@@ -1016,6 +1041,8 @@ class ActionChip extends StatelessWidget implements ChipAttributes, TappableChip
...
@@ -1016,6 +1041,8 @@ class ActionChip extends StatelessWidget implements ChipAttributes, TappableChip
@override
@override
final
ShapeBorder
shape
;
final
ShapeBorder
shape
;
@override
@override
final
Clip
clipBehavior
;
@override
final
Color
backgroundColor
;
final
Color
backgroundColor
;
@override
@override
final
EdgeInsetsGeometry
padding
;
final
EdgeInsetsGeometry
padding
;
...
@@ -1033,6 +1060,7 @@ class ActionChip extends StatelessWidget implements ChipAttributes, TappableChip
...
@@ -1033,6 +1060,7 @@ class ActionChip extends StatelessWidget implements ChipAttributes, TappableChip
labelStyle:
labelStyle
,
labelStyle:
labelStyle
,
backgroundColor:
backgroundColor
,
backgroundColor:
backgroundColor
,
shape:
shape
,
shape:
shape
,
clipBehavior:
clipBehavior
,
padding:
padding
,
padding:
padding
,
labelPadding:
labelPadding
,
labelPadding:
labelPadding
,
isEnabled:
true
,
isEnabled:
true
,
...
@@ -1083,7 +1111,7 @@ class RawChip extends StatefulWidget
...
@@ -1083,7 +1111,7 @@ class RawChip extends StatefulWidget
/// The [onPressed] and [onSelected] callbacks must not both be specified at
/// The [onPressed] and [onSelected] callbacks must not both be specified at
/// the same time.
/// the same time.
///
///
/// The [label]
and [isEnabled
] arguments must not be null.
/// The [label]
, [isEnabled], and [clipBehavior
] arguments must not be null.
const
RawChip
({
const
RawChip
({
Key
key
,
Key
key
,
this
.
avatar
,
this
.
avatar
,
...
@@ -1105,10 +1133,12 @@ class RawChip extends StatefulWidget
...
@@ -1105,10 +1133,12 @@ class RawChip extends StatefulWidget
this
.
selectedColor
,
this
.
selectedColor
,
this
.
tooltip
,
this
.
tooltip
,
this
.
shape
,
this
.
shape
,
this
.
clipBehavior
=
Clip
.
none
,
this
.
backgroundColor
,
this
.
backgroundColor
,
this
.
materialTapTargetSize
,
this
.
materialTapTargetSize
,
})
:
assert
(
label
!=
null
),
})
:
assert
(
label
!=
null
),
assert
(
isEnabled
!=
null
),
assert
(
isEnabled
!=
null
),
assert
(
clipBehavior
!=
null
),
deleteIcon
=
deleteIcon
??
_kDefaultDeleteIcon
,
deleteIcon
=
deleteIcon
??
_kDefaultDeleteIcon
,
super
(
key:
key
);
super
(
key:
key
);
...
@@ -1145,6 +1175,8 @@ class RawChip extends StatefulWidget
...
@@ -1145,6 +1175,8 @@ class RawChip extends StatefulWidget
@override
@override
final
ShapeBorder
shape
;
final
ShapeBorder
shape
;
@override
@override
final
Clip
clipBehavior
;
@override
final
Color
backgroundColor
;
final
Color
backgroundColor
;
@override
@override
final
EdgeInsetsGeometry
padding
;
final
EdgeInsetsGeometry
padding
;
...
@@ -1405,6 +1437,7 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
...
@@ -1405,6 +1437,7 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
elevation:
isTapping
?
_kPressElevation
:
0.0
,
elevation:
isTapping
?
_kPressElevation
:
0.0
,
animationDuration:
pressedAnimationDuration
,
animationDuration:
pressedAnimationDuration
,
shape:
shape
,
shape:
shape
,
clipBehavior:
widget
.
clipBehavior
,
child:
new
InkResponse
(
child:
new
InkResponse
(
onTap:
canTap
?
_handleTap
:
null
,
onTap:
canTap
?
_handleTap
:
null
,
onTapDown:
canTap
?
_handleTapDown
:
null
,
onTapDown:
canTap
?
_handleTapDown
:
null
,
...
...
packages/flutter/lib/src/material/chip_theme.dart
View file @
f7b2722d
...
@@ -298,7 +298,7 @@ class ChipThemeData extends Diagnosticable {
...
@@ -298,7 +298,7 @@ class ChipThemeData extends Diagnosticable {
/// label, and zero on top and bottom.
/// label, and zero on top and bottom.
final
EdgeInsetsGeometry
labelPadding
;
final
EdgeInsetsGeometry
labelPadding
;
/// The padding between the contents of the chip and the outside [
border
].
/// The padding between the contents of the chip and the outside [
shape
].
///
///
/// Defaults to 4 logical pixels on all sides.
/// Defaults to 4 logical pixels on all sides.
final
EdgeInsetsGeometry
padding
;
final
EdgeInsetsGeometry
padding
;
...
...
packages/flutter/test/material/chip_test.dart
View file @
f7b2722d
...
@@ -1442,4 +1442,55 @@ void main() {
...
@@ -1442,4 +1442,55 @@ void main() {
expect
(
find
.
byType
(
InputChip
).
hitTestable
(
at:
Alignment
.
center
),
findsOneWidget
);
expect
(
find
.
byType
(
InputChip
).
hitTestable
(
at:
Alignment
.
center
),
findsOneWidget
);
});
});
void
checkChipMaterialClipBehavior
(
WidgetTester
tester
,
Clip
clipBehavior
)
{
final
Iterable
<
Material
>
materials
=
tester
.
widgetList
<
Material
>(
find
.
byType
(
Material
));
expect
(
materials
.
length
,
2
);
expect
(
materials
.
last
.
clipBehavior
,
clipBehavior
);
}
testWidgets
(
'Chip clipBehavior properly passes through to the Material'
,
(
WidgetTester
tester
)
async
{
const
Text
label
=
Text
(
'label'
);
await
tester
.
pumpWidget
(
_wrapForChip
(
child:
const
Chip
(
label:
label
)));
checkChipMaterialClipBehavior
(
tester
,
Clip
.
none
);
await
tester
.
pumpWidget
(
_wrapForChip
(
child:
const
Chip
(
label:
label
,
clipBehavior:
Clip
.
antiAlias
)));
checkChipMaterialClipBehavior
(
tester
,
Clip
.
antiAlias
);
});
testWidgets
(
'ChoiceChip clipBehavior properly passes through to the Material'
,
(
WidgetTester
tester
)
async
{
const
Text
label
=
Text
(
'label'
);
await
tester
.
pumpWidget
(
_wrapForChip
(
child:
const
ChoiceChip
(
label:
label
,
selected:
false
)));
checkChipMaterialClipBehavior
(
tester
,
Clip
.
none
);
await
tester
.
pumpWidget
(
_wrapForChip
(
child:
const
ChoiceChip
(
label:
label
,
selected:
false
,
clipBehavior:
Clip
.
antiAlias
)));
checkChipMaterialClipBehavior
(
tester
,
Clip
.
antiAlias
);
});
testWidgets
(
'FilterChip clipBehavior properly passes through to the Material'
,
(
WidgetTester
tester
)
async
{
const
Text
label
=
Text
(
'label'
);
await
tester
.
pumpWidget
(
_wrapForChip
(
child:
new
FilterChip
(
label:
label
,
onSelected:
(
bool
b
){},)));
checkChipMaterialClipBehavior
(
tester
,
Clip
.
none
);
await
tester
.
pumpWidget
(
_wrapForChip
(
child:
new
FilterChip
(
label:
label
,
onSelected:
(
bool
b
){},
clipBehavior:
Clip
.
antiAlias
)));
checkChipMaterialClipBehavior
(
tester
,
Clip
.
antiAlias
);
});
testWidgets
(
'ActionChip clipBehavior properly passes through to the Material'
,
(
WidgetTester
tester
)
async
{
const
Text
label
=
Text
(
'label'
);
await
tester
.
pumpWidget
(
_wrapForChip
(
child:
new
ActionChip
(
label:
label
,
onPressed:
(){},)));
checkChipMaterialClipBehavior
(
tester
,
Clip
.
none
);
await
tester
.
pumpWidget
(
_wrapForChip
(
child:
new
ActionChip
(
label:
label
,
clipBehavior:
Clip
.
antiAlias
,
onPressed:
(){})));
checkChipMaterialClipBehavior
(
tester
,
Clip
.
antiAlias
);
});
testWidgets
(
'InputChip clipBehavior properly passes through to the Material'
,
(
WidgetTester
tester
)
async
{
const
Text
label
=
Text
(
'label'
);
await
tester
.
pumpWidget
(
_wrapForChip
(
child:
const
InputChip
(
label:
label
)));
checkChipMaterialClipBehavior
(
tester
,
Clip
.
none
);
await
tester
.
pumpWidget
(
_wrapForChip
(
child:
const
InputChip
(
label:
label
,
clipBehavior:
Clip
.
antiAlias
)));
checkChipMaterialClipBehavior
(
tester
,
Clip
.
antiAlias
);
});
}
}
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