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
e8cbd444
Unverified
Commit
e8cbd444
authored
Nov 17, 2022
by
Hans Muller
Committed by
GitHub
Nov 17, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Badge.isLabelVisible flag (#115292)
parent
1b23ad63
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
badge.dart
packages/flutter/lib/src/material/badge.dart
+11
-0
badge_test.dart
packages/flutter/test/material/badge_test.dart
+24
-2
No files found.
packages/flutter/lib/src/material/badge.dart
View file @
e8cbd444
...
...
@@ -36,6 +36,7 @@ class Badge extends StatelessWidget {
this
.
padding
,
this
.
alignment
,
this
.
label
,
this
.
isLabelVisible
=
true
,
this
.
child
,
});
...
...
@@ -102,6 +103,12 @@ class Badge extends StatelessWidget {
/// this is a [StadiumBorder] shaped "large" badge with height [largeSize].
final
Widget
?
label
;
/// If false, the badge's [label] is not included.
///
/// This flag is true by default. It's intended to make it convenient
/// to create a badge that's only shown under certain conditions.
final
bool
isLabelVisible
;
/// The widget that the badge is stacked on top of.
///
/// Typically this is an default sized [Icon] that's part of a
...
...
@@ -110,6 +117,10 @@ class Badge extends StatelessWidget {
@override
Widget
build
(
BuildContext
context
)
{
if
(!
isLabelVisible
)
{
return
child
??
const
SizedBox
();
}
final
BadgeThemeData
badgeTheme
=
BadgeTheme
.
of
(
context
);
final
BadgeThemeData
defaults
=
_BadgeDefaultsM3
(
context
);
final
double
effectiveSmallSize
=
smallSize
??
badgeTheme
.
smallSize
??
defaults
.
smallSize
!;
...
...
packages/flutter/test/material/badge_test.dart
View file @
e8cbd444
...
...
@@ -20,7 +20,7 @@ void main() {
alignment:
Alignment
.
topLeft
,
child:
Builder
(
builder:
(
BuildContext
context
)
{
// theme.textT
t
heme is updated when the MaterialApp is built.
// theme.textTheme is updated when the MaterialApp is built.
theme
=
Theme
.
of
(
context
);
return
const
Badge
(
label:
Text
(
'0'
),
...
...
@@ -71,7 +71,7 @@ void main() {
alignment:
Alignment
.
topLeft
,
child:
Builder
(
builder:
(
BuildContext
context
)
{
// theme.textT
t
heme is updated when the MaterialApp is built.
// theme.textTheme is updated when the MaterialApp is built.
theme
=
Theme
.
of
(
context
);
return
const
Badge
(
label:
Text
(
'0'
),
...
...
@@ -202,5 +202,27 @@ void main() {
expect
(
tester
.
renderObject
(
find
.
byType
(
Badge
)),
paints
..
rrect
(
color:
black
));
});
testWidgets
(
'isLabelVisible'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
.
light
(
useMaterial3:
true
),
home:
const
Align
(
alignment:
Alignment
.
topLeft
,
child:
Badge
(
label:
Text
(
'0'
),
isLabelVisible:
false
,
child:
Icon
(
Icons
.
add
),
),
),
),
);
expect
(
find
.
text
(
'0'
),
findsNothing
);
expect
(
find
.
byType
(
Icon
),
findsOneWidget
);
expect
(
tester
.
getSize
(
find
.
byType
(
Badge
)),
const
Size
(
24
,
24
));
// default Icon size
expect
(
tester
.
getTopLeft
(
find
.
byType
(
Badge
)),
Offset
.
zero
);
final
RenderBox
box
=
tester
.
renderObject
(
find
.
byType
(
Badge
));
expect
(
box
,
isNot
(
paints
..
rrect
()));
});
}
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