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
a7917414
Unverified
Commit
a7917414
authored
Dec 08, 2021
by
Hans Muller
Committed by
GitHub
Dec 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Corrected a ChipTheme labelStyle corner case (#94818)
parent
76554783
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
12 deletions
+94
-12
chip.dart
packages/flutter/lib/src/material/chip.dart
+6
-5
chip_test.dart
packages/flutter/test/material/chip_test.dart
+88
-7
No files found.
packages/flutter/lib/src/material/chip.dart
View file @
a7917414
...
...
@@ -76,7 +76,8 @@ abstract class ChipAttributes {
/// The style to be applied to the chip's label.
///
/// If null, the value of the [ChipTheme]'s [ChipThemeData.labelStyle] is used.
/// The default label style is [TextTheme.bodyText1] from the overall
/// theme's [ThemeData.textTheme].
//
/// This only has an effect on widgets that respect the [DefaultTextStyle],
/// such as [Text].
...
...
@@ -1898,15 +1899,15 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
??
chipTheme
.
padding
??
theme
.
chipTheme
.
padding
??
chipDefaults
.
padding
!;
final
TextStyle
?
labelStyle
=
widget
.
labelStyle
??
chipTheme
.
labelStyle
??
theme
.
chipTheme
.
labelStyle
;
final
TextStyle
labelStyle
=
chipTheme
.
labelStyle
??
theme
.
chipTheme
.
labelStyle
??
chipDefaults
.
labelStyle
!
;
final
EdgeInsetsGeometry
labelPadding
=
widget
.
labelPadding
??
chipTheme
.
labelPadding
??
theme
.
chipTheme
.
labelPadding
??
_defaultLabelPadding
;
final
TextStyle
effectiveLabelStyle
=
chipDefaults
.
labelStyle
!.
merge
(
labelStyle
);
final
TextStyle
effectiveLabelStyle
=
labelStyle
.
merge
(
widget
.
labelStyle
);
final
Color
?
resolvedLabelColor
=
MaterialStateProperty
.
resolveAs
<
Color
?>(
effectiveLabelStyle
.
color
,
materialStates
);
final
TextStyle
resolvedLabelStyle
=
effectiveLabelStyle
.
copyWith
(
color:
resolvedLabelColor
);
...
...
packages/flutter/test/material/chip_test.dart
View file @
a7917414
...
...
@@ -271,15 +271,22 @@ Finder findTooltipContainer(String tooltipText) {
void
main
(
)
{
testWidgets
(
'Chip defaults'
,
(
WidgetTester
tester
)
async
{
late
TextTheme
textTheme
;
Widget
buildFrame
(
Brightness
brightness
)
{
return
MaterialApp
(
theme:
ThemeData
(
brightness:
brightness
),
home:
Scaffold
(
body:
Center
(
child:
Chip
(
avatar:
const
CircleAvatar
(
child:
Text
(
'A'
)),
label:
const
Text
(
'Chip A'
),
onDeleted:
()
{
},
child:
Builder
(
builder:
(
BuildContext
context
)
{
textTheme
=
Theme
.
of
(
context
).
textTheme
;
return
Chip
(
avatar:
const
CircleAvatar
(
child:
Text
(
'A'
)),
label:
const
Text
(
'Chip A'
),
onDeleted:
()
{
},
);
},
),
),
),
...
...
@@ -295,7 +302,22 @@ void main() {
expect
(
getIconData
(
tester
).
color
?.
value
,
0xffffffff
);
expect
(
getIconData
(
tester
).
opacity
,
null
);
expect
(
getIconData
(
tester
).
size
,
null
);
expect
(
getLabelStyle
(
tester
,
'Chip A'
).
style
.
color
?.
value
,
0xde000000
);
TextStyle
labelStyle
=
getLabelStyle
(
tester
,
'Chip A'
).
style
;
expect
(
labelStyle
.
color
?.
value
,
0xde000000
);
expect
(
labelStyle
.
fontFamily
,
textTheme
.
bodyText1
?.
fontFamily
);
expect
(
labelStyle
.
fontFamilyFallback
,
textTheme
.
bodyText1
?.
fontFamilyFallback
);
expect
(
labelStyle
.
fontFeatures
,
textTheme
.
bodyText1
?.
fontFeatures
);
expect
(
labelStyle
.
fontSize
,
textTheme
.
bodyText1
?.
fontSize
);
expect
(
labelStyle
.
fontStyle
,
textTheme
.
bodyText1
?.
fontStyle
);
expect
(
labelStyle
.
fontWeight
,
textTheme
.
bodyText1
?.
fontWeight
);
expect
(
labelStyle
.
height
,
textTheme
.
bodyText1
?.
height
);
expect
(
labelStyle
.
inherit
,
textTheme
.
bodyText1
?.
inherit
);
expect
(
labelStyle
.
leadingDistribution
,
textTheme
.
bodyText1
?.
leadingDistribution
);
expect
(
labelStyle
.
letterSpacing
,
textTheme
.
bodyText1
?.
letterSpacing
);
expect
(
labelStyle
.
overflow
,
textTheme
.
bodyText1
?.
overflow
);
expect
(
labelStyle
.
textBaseline
,
textTheme
.
bodyText1
?.
textBaseline
);
expect
(
labelStyle
.
wordSpacing
,
textTheme
.
bodyText1
?.
wordSpacing
);
await
tester
.
pumpWidget
(
buildFrame
(
Brightness
.
dark
));
await
tester
.
pumpAndSettle
();
// Theme transition animation
...
...
@@ -307,7 +329,22 @@ void main() {
expect
(
getIconData
(
tester
).
color
?.
value
,
0xffffffff
);
expect
(
getIconData
(
tester
).
opacity
,
null
);
expect
(
getIconData
(
tester
).
size
,
null
);
expect
(
getLabelStyle
(
tester
,
'Chip A'
).
style
.
color
?.
value
,
0xdeffffff
);
labelStyle
=
getLabelStyle
(
tester
,
'Chip A'
).
style
;
expect
(
labelStyle
.
color
?.
value
,
0xdeffffff
);
expect
(
labelStyle
.
fontFamily
,
textTheme
.
bodyText1
?.
fontFamily
);
expect
(
labelStyle
.
fontFamilyFallback
,
textTheme
.
bodyText1
?.
fontFamilyFallback
);
expect
(
labelStyle
.
fontFeatures
,
textTheme
.
bodyText1
?.
fontFeatures
);
expect
(
labelStyle
.
fontSize
,
textTheme
.
bodyText1
?.
fontSize
);
expect
(
labelStyle
.
fontStyle
,
textTheme
.
bodyText1
?.
fontStyle
);
expect
(
labelStyle
.
fontWeight
,
textTheme
.
bodyText1
?.
fontWeight
);
expect
(
labelStyle
.
height
,
textTheme
.
bodyText1
?.
height
);
expect
(
labelStyle
.
inherit
,
textTheme
.
bodyText1
?.
inherit
);
expect
(
labelStyle
.
leadingDistribution
,
textTheme
.
bodyText1
?.
leadingDistribution
);
expect
(
labelStyle
.
letterSpacing
,
textTheme
.
bodyText1
?.
letterSpacing
);
expect
(
labelStyle
.
overflow
,
textTheme
.
bodyText1
?.
overflow
);
expect
(
labelStyle
.
textBaseline
,
textTheme
.
bodyText1
?.
textBaseline
);
expect
(
labelStyle
.
wordSpacing
,
textTheme
.
bodyText1
?.
wordSpacing
);
});
testWidgets
(
'ChoiceChip defaults'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -343,7 +380,6 @@ void main() {
expect
(
getLabelStyle
(
tester
,
'Chip A'
).
style
.
color
?.
value
,
0xdeffffff
);
});
testWidgets
(
'Chip control test'
,
(
WidgetTester
tester
)
async
{
final
FeedbackTester
feedback
=
FeedbackTester
();
final
List
<
String
>
deletedChipLabels
=
<
String
>[];
...
...
@@ -1726,10 +1762,55 @@ void main() {
await
tester
.
pumpWidget
(
buildChip
());
final
TextStyle
labelStyle
=
getLabelStyle
(
tester
,
'Label'
).
style
;
expect
(
labelStyle
.
inherit
,
false
);
expect
(
labelStyle
.
fontFamily
,
'MyFont'
);
expect
(
labelStyle
.
fontWeight
,
FontWeight
.
w200
);
});
testWidgets
(
'ChipTheme labelStyle with inherit:true'
,
(
WidgetTester
tester
)
async
{
Widget
buildChip
()
{
return
_wrapForChip
(
child:
Theme
(
data:
ThemeData
.
light
().
copyWith
(
chipTheme:
const
ChipThemeData
(
labelStyle:
TextStyle
(
height:
4
),
// inherit: true
),
),
child:
const
Chip
(
label:
Text
(
'Label'
)),
// labeStyle: null
),
);
}
await
tester
.
pumpWidget
(
buildChip
());
final
TextStyle
labelStyle
=
getLabelStyle
(
tester
,
'Label'
).
style
;
expect
(
labelStyle
.
inherit
,
true
);
// because chipTheme.labelStyle.merge(null)
expect
(
labelStyle
.
height
,
4
);
});
testWidgets
(
'Chip does not merge inherit:false label style with the theme label style'
,
(
WidgetTester
tester
)
async
{
Widget
buildChip
()
{
return
_wrapForChip
(
child:
Theme
(
data:
ThemeData
(
fontFamily:
'MyFont'
),
child:
const
DefaultTextStyle
(
style:
TextStyle
(
height:
8
),
child:
Chip
(
label:
Text
(
'Label'
),
labelStyle:
TextStyle
(
fontWeight:
FontWeight
.
w200
,
inherit:
false
),
),
),
),
);
}
await
tester
.
pumpWidget
(
buildChip
());
final
TextStyle
labelStyle
=
getLabelStyle
(
tester
,
'Label'
).
style
;
expect
(
labelStyle
.
inherit
,
false
);
expect
(
labelStyle
.
fontFamily
,
null
);
expect
(
labelStyle
.
height
,
null
);
expect
(
labelStyle
.
fontWeight
,
FontWeight
.
w200
);
});
testWidgets
(
'Chip size is configurable by ThemeData.materialTapTargetSize'
,
(
WidgetTester
tester
)
async
{
final
Key
key1
=
UniqueKey
();
await
tester
.
pumpWidget
(
...
...
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