@@ -283,53 +283,6 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
283
283
284
284
@override
285
285
Widget build (BuildContext context) {
286
- final store = PerAccountStoreWidget .of (context);
287
- final messageListTheme = MessageListTheme .of (context);
288
- final zulipLocalizations = ZulipLocalizations .of (context);
289
-
290
- final Color ? appBarBackgroundColor;
291
- bool removeAppBarBottomBorder = false ;
292
- switch (narrow) {
293
- case CombinedFeedNarrow ():
294
- case MentionsNarrow ():
295
- case StarredMessagesNarrow ():
296
- appBarBackgroundColor = null ; // i.e., inherit
297
-
298
- case ChannelNarrow (: final streamId):
299
- case TopicNarrow (: final streamId):
300
- final subscription = store.subscriptions[streamId];
301
- appBarBackgroundColor =
302
- colorSwatchFor (context, subscription).barBackground;
303
- // All recipient headers will match this color; remove distracting line
304
- // (but are recipient headers even needed for topic narrows?)
305
- removeAppBarBottomBorder = true ;
306
-
307
- case DmNarrow ():
308
- appBarBackgroundColor = messageListTheme.dmRecipientHeaderBg;
309
- // All recipient headers will match this color; remove distracting line
310
- // (but are recipient headers even needed?)
311
- removeAppBarBottomBorder = true ;
312
- }
313
-
314
- List <Widget > actions = [];
315
- switch (narrow) {
316
- case CombinedFeedNarrow ():
317
- case MentionsNarrow ():
318
- case StarredMessagesNarrow ():
319
- case DmNarrow ():
320
- break ;
321
- case ChannelNarrow (: final streamId):
322
- actions.add (_TopicListButton (streamId: streamId));
323
- case TopicNarrow (: final streamId):
324
- actions.add (IconButton (
325
- icon: const Icon (ZulipIcons .message_feed),
326
- tooltip: zulipLocalizations.channelFeedButtonTooltip,
327
- onPressed: () => Navigator .push (context,
328
- MessageListPage .buildRoute (context: context,
329
- narrow: ChannelNarrow (streamId)))));
330
- actions.add (_TopicListButton (streamId: streamId));
331
- }
332
-
333
286
final Anchor initAnchor;
334
287
if (widget.initAnchorMessageId != null ) {
335
288
initAnchor = NumericAnchor (widget.initAnchorMessageId! );
@@ -340,15 +293,7 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
340
293
}
341
294
342
295
Widget result = Scaffold (
343
- appBar: ZulipAppBar (
344
- buildTitle: (willCenterTitle) =>
345
- MessageListAppBarTitle (narrow: narrow, willCenterTitle: willCenterTitle),
346
- actions: actions,
347
- backgroundColor: appBarBackgroundColor,
348
- shape: removeAppBarBottomBorder
349
- ? const Border ()
350
- : null , // i.e., inherit
351
- ),
296
+ appBar: _MessageListAppBar .build (context, narrow: narrow),
352
297
// TODO question for Vlad: for a stream view, should we set the Scaffold's
353
298
// [backgroundColor] based on stream color, as in this frame:
354
299
// https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=132%3A9684&mode=dev
@@ -397,6 +342,77 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
397
342
}
398
343
}
399
344
345
+ // Conceptually this should be a widget class. But it needs to be a
346
+ // PreferredSizeWidget, with the `preferredSize` that the underlying AppBar
347
+ // will have... and there's currently no good way to get that value short of
348
+ // constructing the whole AppBar widget with all its properties.
349
+ // So this has to be built eagerly by its parent's build method,
350
+ // making it a build function rather than a widget. Discussion:
351
+ // https://github.com/zulip/zulip-flutter/pull/1662#discussion_r2183471883
352
+ // Still we can organize it on a class, with the name the widget would have.
353
+ // TODO(upstream): AppBar should expose a bit more API so that it's possible
354
+ // to customize by composition in a reasonable way.
355
+ abstract class _MessageListAppBar {
356
+ static AppBar build (BuildContext context, {required Narrow narrow}) {
357
+ final store = PerAccountStoreWidget .of (context);
358
+ final messageListTheme = MessageListTheme .of (context);
359
+ final zulipLocalizations = ZulipLocalizations .of (context);
360
+
361
+ final Color ? appBarBackgroundColor;
362
+ bool removeAppBarBottomBorder = false ;
363
+ switch (narrow) {
364
+ case CombinedFeedNarrow ():
365
+ case MentionsNarrow ():
366
+ case StarredMessagesNarrow ():
367
+ appBarBackgroundColor = null ; // i.e., inherit
368
+
369
+ case ChannelNarrow (: final streamId):
370
+ case TopicNarrow (: final streamId):
371
+ final subscription = store.subscriptions[streamId];
372
+ appBarBackgroundColor =
373
+ colorSwatchFor (context, subscription).barBackground;
374
+ // All recipient headers will match this color; remove distracting line
375
+ // (but are recipient headers even needed for topic narrows?)
376
+ removeAppBarBottomBorder = true ;
377
+
378
+ case DmNarrow ():
379
+ appBarBackgroundColor = messageListTheme.dmRecipientHeaderBg;
380
+ // All recipient headers will match this color; remove distracting line
381
+ // (but are recipient headers even needed?)
382
+ removeAppBarBottomBorder = true ;
383
+ }
384
+
385
+ List <Widget > actions = [];
386
+ switch (narrow) {
387
+ case CombinedFeedNarrow ():
388
+ case MentionsNarrow ():
389
+ case StarredMessagesNarrow ():
390
+ case DmNarrow ():
391
+ break ;
392
+ case ChannelNarrow (: final streamId):
393
+ actions.add (_TopicListButton (streamId: streamId));
394
+ case TopicNarrow (: final streamId):
395
+ actions.add (IconButton (
396
+ icon: const Icon (ZulipIcons .message_feed),
397
+ tooltip: zulipLocalizations.channelFeedButtonTooltip,
398
+ onPressed: () => Navigator .push (context,
399
+ MessageListPage .buildRoute (context: context,
400
+ narrow: ChannelNarrow (streamId)))));
401
+ actions.add (_TopicListButton (streamId: streamId));
402
+ }
403
+
404
+ return ZulipAppBar (
405
+ buildTitle: (willCenterTitle) =>
406
+ MessageListAppBarTitle (narrow: narrow, willCenterTitle: willCenterTitle),
407
+ actions: actions,
408
+ backgroundColor: appBarBackgroundColor,
409
+ shape: removeAppBarBottomBorder
410
+ ? const Border ()
411
+ : null , // i.e., inherit
412
+ );
413
+ }
414
+ }
415
+
400
416
class RevealedMutedMessagesState extends ChangeNotifier {
401
417
final Set <int > _revealedMessages = {};
402
418
0 commit comments