Skip to content

Commit d9eb0d3

Browse files
committed
widgets: Pull out reusable UnreadCountBadge widget
1 parent e7fe06c commit d9eb0d3

File tree

3 files changed

+56
-20
lines changed

3 files changed

+56
-20
lines changed

lib/widgets/recent_dm_conversations.dart

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'dart:ui';
2-
31
import 'package:flutter/material.dart';
42

53
import '../model/narrow.dart';
@@ -11,6 +9,7 @@ import 'message_list.dart';
119
import 'page.dart';
1210
import 'store.dart';
1311
import 'text.dart';
12+
import 'unread_count_badge.dart';
1413

1514
class RecentDmConversationsPage extends StatefulWidget {
1615
const RecentDmConversationsPage({super.key});
@@ -132,24 +131,8 @@ class RecentDmConversationsItem extends StatelessWidget {
132131
title))),
133132
const SizedBox(width: 12),
134133
unreadCount > 0
135-
? Padding(
136-
padding: const EdgeInsetsDirectional.only(end: 16),
137-
child: DecoratedBox(
138-
decoration: BoxDecoration(
139-
borderRadius: BorderRadius.circular(3),
140-
color: const Color.fromRGBO(102, 102, 153, 0.15),
141-
),
142-
child: Padding(
143-
padding: const EdgeInsetsDirectional.fromSTEB(4, 0, 4, 1),
144-
child: Text(
145-
style: const TextStyle(
146-
fontFamily: 'Source Sans 3',
147-
fontSize: 16,
148-
height: (18 / 16),
149-
fontFeatures: [FontFeature.enable('smcp')], // small caps
150-
color: Color(0xFF222222),
151-
).merge(weightVariableTextStyle(context)),
152-
unreadCount.toString()))))
134+
? Padding(padding: const EdgeInsetsDirectional.only(end: 16),
135+
child: UnreadCountBadge(count: unreadCount))
153136
: const SizedBox(),
154137
])));
155138
}

lib/widgets/unread_count_badge.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'dart:ui';
2+
3+
import 'package:flutter/material.dart';
4+
5+
import 'text.dart';
6+
7+
/// A widget to display a given number of unreads in a conversation.
8+
///
9+
/// Implements the design for these in Figma:
10+
/// <https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=341%3A12387&mode=dev>
11+
class UnreadCountBadge extends StatelessWidget {
12+
const UnreadCountBadge({
13+
super.key,
14+
required this.count,
15+
});
16+
17+
final int count;
18+
19+
@override
20+
Widget build(BuildContext context) {
21+
return DecoratedBox(
22+
decoration: BoxDecoration(
23+
borderRadius: BorderRadius.circular(3),
24+
color: const Color.fromRGBO(102, 102, 153, 0.15),
25+
),
26+
child: Padding(
27+
padding: const EdgeInsetsDirectional.fromSTEB(4, 0, 4, 1),
28+
child: Text(
29+
style: const TextStyle(
30+
fontFamily: 'Source Sans 3',
31+
fontSize: 16,
32+
height: (18 / 16),
33+
fontFeatures: [FontFeature.enable('smcp')], // small caps
34+
color: Color(0xFF222222),
35+
).merge(weightVariableTextStyle(context)),
36+
count.toString())));
37+
}
38+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'package:flutter/widgets.dart';
2+
3+
import 'package:flutter_test/flutter_test.dart';
4+
import 'package:zulip/widgets/unread_count_badge.dart';
5+
6+
void main() {
7+
group('UnreadCountBadge', () {
8+
testWidgets('smoke test; no crash', (tester) async {
9+
await tester.pumpWidget(
10+
const Directionality(textDirection: TextDirection.ltr,
11+
child: UnreadCountBadge(count: 1)));
12+
tester.widget(find.text("1"));
13+
});
14+
});
15+
}

0 commit comments

Comments
 (0)