@@ -111,6 +111,63 @@ void main() {
111
111
expect (box, paints..rrect (rrect: RRect .fromLTRBR (- 8 , - 4 , 12 , 12 , const Radius .circular (8 )), color: theme.colorScheme.error));
112
112
});
113
113
114
+ // Essentially the same as 'Large Badge defaults'
115
+ testWidgets ('Badge.count' , (WidgetTester tester) async {
116
+ late final ThemeData theme;
117
+
118
+ Widget buildFrame (int count) {
119
+ return MaterialApp (
120
+ theme: ThemeData .light (useMaterial3: true ),
121
+ home: Align (
122
+ alignment: Alignment .topLeft,
123
+ child: Builder (
124
+ builder: (BuildContext context) {
125
+ // theme.textTheme is updated when the MaterialApp is built.
126
+ if (count == 0 ) {
127
+ theme = Theme .of (context);
128
+ }
129
+ return Badge .count (
130
+ count: count,
131
+ child: const Icon (Icons .add),
132
+ );
133
+ },
134
+ ),
135
+ ),
136
+ );
137
+ }
138
+
139
+ await tester.pumpWidget (buildFrame (0 ));
140
+
141
+ expect (
142
+ tester.renderObject <RenderParagraph >(find.text ('0' )).text.style,
143
+ theme.textTheme.labelSmall! .copyWith (color: theme.colorScheme.onError),
144
+ );
145
+
146
+ // default badge alignment = AlignmentDirectional(12, -4)
147
+ // default padding = EdgeInsets.symmetric(horizontal: 4)
148
+ // default largeSize = 16
149
+ // '0'.width = 12
150
+ // icon.width = 24
151
+
152
+ expect (tester.getSize (find.byType (Badge )), const Size (24 , 24 )); // default Icon size
153
+ expect (tester.getTopLeft (find.byType (Badge )), Offset .zero);
154
+
155
+ // x = alignment.start + padding.left
156
+ // y = alignment.top
157
+ expect (tester.getTopLeft (find.text ('0' )), const Offset (16 , - 4 ));
158
+
159
+ final RenderBox box = tester.renderObject (find.byType (Badge ));
160
+ // '0'.width = 12
161
+ // L = alignment.start
162
+ // T = alignment.top
163
+ // R = L + '0'.width + padding.width
164
+ // B = T + largeSize, R = largeSize/2
165
+ expect (box, paints..rrect (rrect: RRect .fromLTRBR (12 , - 4 , 32 , 12 , const Radius .circular (8 )), color: theme.colorScheme.error));
166
+
167
+ await tester.pumpWidget (buildFrame (1000 ));
168
+ expect (find.text ('999+' ), findsOneWidget);
169
+ });
170
+
114
171
testWidgets ('Small Badge defaults' , (WidgetTester tester) async {
115
172
final ThemeData theme = ThemeData .light (useMaterial3: true );
116
173
0 commit comments