Skip to content

Commit e97e6fd

Browse files
committed
msglist: Apply subscription color to StreamMessageRecipientHeader
1 parent a56577a commit e97e6fd

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
@@ -554,11 +554,19 @@ class StreamMessageRecipientHeader extends StatelessWidget {
554554
final topic = message.subject;
555555

556556
final subscription = store.subscriptions[message.streamId];
557-
final streamColor = Color(subscription?.color ?? 0x00c2c2c2);
558-
final contrastingColor =
559-
ThemeData.estimateBrightnessForColor(streamColor) == Brightness.dark
560-
? Colors.white
561-
: Colors.black;
557+
final Color backgroundColor;
558+
final Color contrastingColor;
559+
if (subscription != null) {
560+
final swatch = subscription.colorSwatch();
561+
backgroundColor = swatch.barBackground;
562+
contrastingColor =
563+
(ThemeData.estimateBrightnessForColor(swatch.barBackground) == Brightness.dark)
564+
? Colors.white
565+
: Colors.black;
566+
} else {
567+
backgroundColor = _kFallbackStreamColor;
568+
contrastingColor = Colors.black;
569+
}
562570
final textStyle = TextStyle(
563571
color: contrastingColor,
564572
);
@@ -593,7 +601,7 @@ class StreamMessageRecipientHeader extends StatelessWidget {
593601
MessageListPage.buildRoute(context: context,
594602
narrow: TopicNarrow.ofMessage(message))),
595603
child: ColoredBox(
596-
color: _kStreamMessageBorderColor,
604+
color: backgroundColor,
597605
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
598606
// TODO(#282): Long stream name will break layout; find a fix.
599607
streamWidget,
@@ -609,13 +617,11 @@ class StreamMessageRecipientHeader extends StatelessWidget {
609617
// TODO topic links?
610618
// Then web also has edit/resolve/mute buttons. Skip those for mobile.
611619
RecipientHeaderDate(message: message,
612-
color: _kRecipientHeaderDateColor),
620+
color: contrastingColor.withOpacity(0.4)),
613621
])));
614622
}
615623
}
616624

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

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)