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
e9622ce9
Unverified
Commit
e9622ce9
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.count constructor (#115297)
parent
e8cbd444
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
0 deletions
+75
-0
badge.dart
packages/flutter/lib/src/material/badge.dart
+18
-0
badge_test.dart
packages/flutter/test/material/badge_test.dart
+57
-0
No files found.
packages/flutter/lib/src/material/badge.dart
View file @
e9622ce9
...
@@ -40,6 +40,24 @@ class Badge extends StatelessWidget {
...
@@ -40,6 +40,24 @@ class Badge extends StatelessWidget {
this
.
child
,
this
.
child
,
});
});
/// Convenience constructor for creating a badge with a numeric
/// label with 1-3 digits based on [count].
///
/// Initializes [label] with a [Text] widget that contains [count].
/// If [count] is greater than 999, then the label is '999+'.
Badge
.
count
({
super
.
key
,
this
.
backgroundColor
,
this
.
textColor
,
this
.
smallSize
,
this
.
largeSize
,
this
.
textStyle
,
this
.
padding
,
this
.
alignment
,
required
int
count
,
this
.
child
,
})
:
label
=
Text
(
count
>
999
?
'999+'
:
'
$count
'
);
/// The badge's fill color.
/// The badge's fill color.
///
///
/// Defaults to the [BadgeTheme]'s background color, or
/// Defaults to the [BadgeTheme]'s background color, or
...
...
packages/flutter/test/material/badge_test.dart
View file @
e9622ce9
...
@@ -111,6 +111,63 @@ void main() {
...
@@ -111,6 +111,63 @@ void main() {
expect
(
box
,
paints
..
rrect
(
rrect:
RRect
.
fromLTRBR
(-
8
,
-
4
,
12
,
12
,
const
Radius
.
circular
(
8
)),
color:
theme
.
colorScheme
.
error
));
expect
(
box
,
paints
..
rrect
(
rrect:
RRect
.
fromLTRBR
(-
8
,
-
4
,
12
,
12
,
const
Radius
.
circular
(
8
)),
color:
theme
.
colorScheme
.
error
));
});
});
// Essentially the same as 'Large Badge defaults'
testWidgets
(
'Badge.count'
,
(
WidgetTester
tester
)
async
{
late
final
ThemeData
theme
;
Widget
buildFrame
(
int
count
)
{
return
MaterialApp
(
theme:
ThemeData
.
light
(
useMaterial3:
true
),
home:
Align
(
alignment:
Alignment
.
topLeft
,
child:
Builder
(
builder:
(
BuildContext
context
)
{
// theme.textTheme is updated when the MaterialApp is built.
if
(
count
==
0
)
{
theme
=
Theme
.
of
(
context
);
}
return
Badge
.
count
(
count:
count
,
child:
const
Icon
(
Icons
.
add
),
);
},
),
),
);
}
await
tester
.
pumpWidget
(
buildFrame
(
0
));
expect
(
tester
.
renderObject
<
RenderParagraph
>(
find
.
text
(
'0'
)).
text
.
style
,
theme
.
textTheme
.
labelSmall
!.
copyWith
(
color:
theme
.
colorScheme
.
onError
),
);
// default badge alignment = AlignmentDirectional(12, -4)
// default padding = EdgeInsets.symmetric(horizontal: 4)
// default largeSize = 16
// '0'.width = 12
// icon.width = 24
expect
(
tester
.
getSize
(
find
.
byType
(
Badge
)),
const
Size
(
24
,
24
));
// default Icon size
expect
(
tester
.
getTopLeft
(
find
.
byType
(
Badge
)),
Offset
.
zero
);
// x = alignment.start + padding.left
// y = alignment.top
expect
(
tester
.
getTopLeft
(
find
.
text
(
'0'
)),
const
Offset
(
16
,
-
4
));
final
RenderBox
box
=
tester
.
renderObject
(
find
.
byType
(
Badge
));
// '0'.width = 12
// L = alignment.start
// T = alignment.top
// R = L + '0'.width + padding.width
// B = T + largeSize, R = largeSize/2
expect
(
box
,
paints
..
rrect
(
rrect:
RRect
.
fromLTRBR
(
12
,
-
4
,
32
,
12
,
const
Radius
.
circular
(
8
)),
color:
theme
.
colorScheme
.
error
));
await
tester
.
pumpWidget
(
buildFrame
(
1000
));
expect
(
find
.
text
(
'999+'
),
findsOneWidget
);
});
testWidgets
(
'Small Badge defaults'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Small Badge defaults'
,
(
WidgetTester
tester
)
async
{
final
ThemeData
theme
=
ThemeData
.
light
(
useMaterial3:
true
);
final
ThemeData
theme
=
ThemeData
.
light
(
useMaterial3:
true
);
...
...
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