Skip to content

Commit 3ecadf2

Browse files
committed
wip use AppBar.preferredSizeFor to clean up _MessageListAppBar
1 parent ac6c750 commit 3ecadf2

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

lib/widgets/app_bar.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class ZulipAppBar extends AppBar {
2929
bottom: _ZulipAppBarBottom(backgroundColor: backgroundColor),
3030
title: title ?? _Title(centerTitle: centerTitle, actions: actions, buildTitle: buildTitle!)
3131
);
32+
33+
static Size preferredSizeFor() {
34+
return AppBar.preferredSizeFor(
35+
bottomPreferredSize: _ZulipAppBarBottom.preferredSizeFor());
36+
}
3237
}
3338

3439
class _Title extends StatelessWidget {
@@ -69,12 +74,14 @@ class _Title extends StatelessWidget {
6974
}
7075

7176
class _ZulipAppBarBottom extends StatelessWidget implements PreferredSizeWidget {
72-
const _ZulipAppBarBottom({this.backgroundColor});
77+
_ZulipAppBarBottom({this.backgroundColor});
7378

7479
final Color? backgroundColor;
7580

7681
@override
77-
Size get preferredSize => const Size.fromHeight(4.0);
82+
final Size preferredSize = preferredSizeFor();
83+
84+
static Size preferredSizeFor() => const Size.fromHeight(4.0);
7885

7986
@override
8087
Widget build(BuildContext context) {

lib/widgets/message_list.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
295295
}
296296

297297
Widget result = Scaffold(
298-
appBar: _MessageListAppBar.build(context, narrow: narrow),
298+
appBar: _MessageListAppBar(narrow: narrow),
299299
// TODO question for Vlad: for a stream view, should we set the Scaffold's
300300
// [backgroundColor] based on stream color, as in this frame:
301301
// https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=132%3A9684&mode=dev
@@ -370,18 +370,18 @@ class _RevealedMutedMessagesProvider extends InheritedNotifier<RevealedMutedMess
370370
RevealedMutedMessagesState get state => notifier!;
371371
}
372372

373-
// Conceptually this should be a widget class. But it needs to be a
374-
// PreferredSizeWidget, with the `preferredSize` that the underlying AppBar
375-
// will have... and there's currently no good way to get that value short of
376-
// constructing the whole AppBar widget with all its properties.
377-
// So this has to be built eagerly by its parent's build method,
378-
// making it a build function rather than a widget. Discussion:
379-
// https://github.com/zulip/zulip-flutter/pull/1662#discussion_r2183471883
380-
// Still we can organize it on a class, with the name the widget would have.
381-
// TODO(upstream): AppBar should expose a bit more API so that it's possible
382-
// to customize by composition in a reasonable way.
383-
abstract class _MessageListAppBar {
384-
static AppBar build(BuildContext context, {required Narrow narrow}) {
373+
class _MessageListAppBar extends StatelessWidget implements PreferredSizeWidget {
374+
_MessageListAppBar({required this.narrow});
375+
376+
final Narrow narrow;
377+
378+
@override
379+
final Size preferredSize = preferredSizeFor();
380+
381+
static Size preferredSizeFor() => ZulipAppBar.preferredSizeFor();
382+
383+
@override
384+
Widget build(BuildContext context) {
385385
final store = PerAccountStoreWidget.of(context);
386386
final messageListTheme = MessageListTheme.of(context);
387387
final zulipLocalizations = ZulipLocalizations.of(context);

0 commit comments

Comments
 (0)