Skip to content

Commit a9c144f

Browse files
committed
msglist: Apply subscription color to StreamMessageRecipientHeader
1 parent 7e24221 commit a9c144f

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

lib/widgets/message_list.dart

+15-9
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,19 @@ class StreamMessageRecipientHeader extends StatelessWidget {
553553

554554
final topic = message.subject;
555555
final subscription = store.subscriptions[message.streamId];
556-
final streamColor = Color(subscription?.color ?? 0x00c2c2c2);
557-
final contrastingColor =
558-
ThemeData.estimateBrightnessForColor(streamColor) == Brightness.dark
559-
? Colors.white
560-
: Colors.black;
556+
final Color backgroundColor;
557+
final Color contrastingColor;
558+
if (subscription != null) {
559+
final swatch = subscription.colorSwatch();
560+
backgroundColor = swatch.barBackground;
561+
contrastingColor =
562+
(ThemeData.estimateBrightnessForColor(swatch.barBackground) == Brightness.dark)
563+
? Colors.white
564+
: Colors.black;
565+
} else {
566+
backgroundColor = _kFallbackStreamColor;
567+
contrastingColor = Colors.black;
568+
}
561569
final textStyle = TextStyle(
562570
color: contrastingColor,
563571
);
@@ -592,7 +600,7 @@ class StreamMessageRecipientHeader extends StatelessWidget {
592600
MessageListPage.buildRoute(context: context,
593601
narrow: TopicNarrow.ofMessage(message))),
594602
child: ColoredBox(
595-
color: _kStreamMessageBorderColor,
603+
color: backgroundColor,
596604
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
597605
// TODO(#282): Long stream name will break layout; find a fix.
598606
streamWidget,
@@ -608,13 +616,11 @@ class StreamMessageRecipientHeader extends StatelessWidget {
608616
// TODO topic links?
609617
// Then web also has edit/resolve/mute buttons. Skip those for mobile.
610618
RecipientHeaderDate(message: message,
611-
color: _kRecipientHeaderDateColor),
619+
color: contrastingColor.withOpacity(0.4)),
612620
])));
613621
}
614622
}
615623

616-
final _kStreamMessageBorderColor = const HSLColor.fromAHSL(1, 0, 0, 0.88).toColor();
617-
618624
class DmRecipientHeader extends StatelessWidget {
619625
const DmRecipientHeader({super.key, required this.message});
620626

test/flutter_checks.dart

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ extension ClipboardDataChecks on Subject<ClipboardData> {
1616
Subject<String?> get text => has((d) => d.text, 'text');
1717
}
1818

19+
extension ColoredBoxChecks on Subject<ColoredBox> {
20+
Subject<Color?> get color => has((d) => d.color, 'color');
21+
}
22+
1923
extension GlobalKeyChecks<T extends State<StatefulWidget>> on Subject<GlobalKey<T>> {
2024
Subject<BuildContext?> get currentContext => has((k) => k.currentContext, 'currentContext');
2125
Subject<Widget?> get currentWidget => has((k) => k.currentWidget, 'currentWidget');

test/widgets/message_list_test.dart

+17-1
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ void main() {
4141
int? messageCount,
4242
List<Message>? messages,
4343
List<ZulipStream>? streams,
44+
List<Subscription>? subscriptions,
4445
UnreadMessagesSnapshot? unreadMsgs,
4546
}) async {
4647
addTearDown(testBinding.reset);
48+
streams ??= subscriptions;
4749
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot(
48-
streams: streams, unreadMsgs: unreadMsgs));
50+
streams: streams, subscriptions: subscriptions, unreadMsgs: unreadMsgs));
4951
store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
5052
connection = store.connection as FakeApiConnection;
5153

@@ -233,6 +235,20 @@ void main() {
233235
check(findInMessageList('stream name')).length.equals(0);
234236
check(findInMessageList('topic name')).length.equals(1);
235237
});
238+
239+
testWidgets('color of recipient header background', (tester) async {
240+
final subscription = eg.subscription(stream, color: Colors.red.value);
241+
final swatch = subscription.colorSwatch();
242+
await setupMessageListPage(tester,
243+
messages: [eg.streamMessage(stream: subscription)],
244+
subscriptions: [subscription]);
245+
await tester.pump();
246+
check(tester.widget<ColoredBox>(
247+
find.descendant(
248+
of: find.byType(StreamMessageRecipientHeader),
249+
matching: find.byType(ColoredBox),
250+
))).color.equals(swatch.barBackground);
251+
});
236252
});
237253

238254
testWidgets('show stream name from message when stream unknown', (tester) async {

0 commit comments

Comments
 (0)