Skip to content

Commit 22b03d5

Browse files
chrisbobbegnprice
authored andcommitted
unread_count_badge [nfc]: Remove extra API for specific background color
Previously, this widget had three options for the background color: 1. Colorized for a channel: callers could pass a ChannelColorSwatch, and the implementation would pick `unreadCountBadgeBackground` off of that. 2. Any `Color`. 3. A default, chosen by the implementation. One caller was using option 2 when option 1 would be a better fit: it wanted a channel-colored background, but it was picking `unreadCountBadgeBackground` itself from the ChannelColorSwatch instead of letting the implementation do that. After changing that caller to just pass the ChannelColorSwatch (option 1), no more callers use option 2, so we remove it. Now UnreadCountBadge has a tighter interface. Next we'll encapsulate finding the channel color swatch itself, so callers only need to have a channel ID if they want a channel-colored background.
1 parent 840e52d commit 22b03d5

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

lib/widgets/inbox.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import '../model/narrow.dart';
66
import '../model/recent_dm_conversations.dart';
77
import '../model/unreads.dart';
88
import 'action_sheet.dart';
9+
import 'channel_colors.dart';
910
import 'icons.dart';
1011
import 'message_list.dart';
1112
import 'page.dart';
@@ -249,7 +250,7 @@ abstract class _HeaderItem extends StatelessWidget {
249250
Color collapsedIconColor(BuildContext context);
250251
Color uncollapsedIconColor(BuildContext context);
251252
Color uncollapsedBackgroundColor(BuildContext context);
252-
Color? unreadCountBadgeBackgroundColor(BuildContext context);
253+
ChannelColorSwatch? unreadCountBadgeBackgroundColor(BuildContext context);
253254

254255
Future<void> onCollapseButtonTap() async {
255256
if (!collapsed) {
@@ -332,7 +333,7 @@ class _AllDmsHeaderItem extends _HeaderItem {
332333
@override Color uncollapsedIconColor(context) => DesignVariables.of(context).labelMenuButton;
333334

334335
@override Color uncollapsedBackgroundColor(context) => DesignVariables.of(context).dmHeaderBg;
335-
@override Color? unreadCountBadgeBackgroundColor(context) => null;
336+
@override ChannelColorSwatch? unreadCountBadgeBackgroundColor(context) => null;
336337

337338
@override Future<void> onCollapseButtonTap() async {
338339
await super.onCollapseButtonTap();
@@ -462,7 +463,7 @@ class _StreamHeaderItem extends _HeaderItem with _LongPressable {
462463
colorSwatchFor(context, subscription).iconOnBarBackground;
463464
@override Color uncollapsedBackgroundColor(context) =>
464465
colorSwatchFor(context, subscription).barBackground;
465-
@override Color? unreadCountBadgeBackgroundColor(context) =>
466+
@override ChannelColorSwatch? unreadCountBadgeBackgroundColor(context) =>
466467
colorSwatchFor(context, subscription);
467468

468469
@override Future<void> onCollapseButtonTap() async {

lib/widgets/unread_count_badge.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,19 @@ class UnreadCountBadge extends StatelessWidget {
1919
final int count;
2020
final bool bold;
2121

22-
/// The badge's background color.
22+
/// An optional [ChannelColorSwatch], to override the default color scheme
23+
/// with a channel-colorized one.
2324
///
24-
/// Pass a [ChannelColorSwatch] if this badge represents messages in one
25-
/// specific stream. The appropriate color from the swatch will be used.
26-
///
27-
/// If null, the default neutral background will be used.
28-
final Color? backgroundColor;
25+
/// Pass this if the badge represents messages in one specific stream.
26+
/// The appropriate color from the swatch will be used.
27+
final ChannelColorSwatch? backgroundColor;
2928

3029
@override
3130
Widget build(BuildContext context) {
3231
final designVariables = DesignVariables.of(context);
3332

3433
final effectiveBackgroundColor = switch (backgroundColor) {
3534
ChannelColorSwatch(unreadCountBadgeBackground: var color) => color,
36-
Color() => backgroundColor,
3735
null => designVariables.bgCounterUnread,
3836
};
3937

test/widgets/unread_count_badge_test.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void main() {
2222
});
2323

2424
group('background', () {
25-
Future<void> prepare(WidgetTester tester, Color? backgroundColor) async {
25+
Future<void> prepare(WidgetTester tester, ChannelColorSwatch? backgroundColor) async {
2626
addTearDown(testBinding.reset);
2727
await tester.pumpWidget(TestZulipApp(
2828
child: UnreadCountBadge(count: 1, backgroundColor: backgroundColor)));
@@ -40,11 +40,6 @@ void main() {
4040
check(findBackgroundColor(tester)).isNotNull().isSameColorAs(const Color(0x26666699));
4141
});
4242

43-
testWidgets('specified color', (tester) async {
44-
await prepare(tester, Colors.pink);
45-
check(findBackgroundColor(tester)).isNotNull().isSameColorAs(Colors.pink);
46-
});
47-
4843
testWidgets('stream color', (tester) async {
4944
final swatch = ChannelColorSwatch.light(0xff76ce90);
5045
await prepare(tester, swatch);

0 commit comments

Comments
 (0)