Skip to content

Commit 0f3c452

Browse files
committed
msglist [nfc]: Make narrow mutable for _MessageListPageState.
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 9e0da39 commit 0f3c452

File tree

11 files changed

+25
-18
lines changed

11 files changed

+25
-18
lines changed

integration_test/unreadmarker_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void main() {
4040
child: PerAccountStoreWidget(
4141
accountId: eg.selfAccount.id,
4242
placeholder: const LoadingPlaceholderPage(),
43-
child: const MessageListPage(narrow: CombinedFeedNarrow())))));
43+
child: const MessageListPage(initNarrow: CombinedFeedNarrow())))));
4444
await tester.pumpAndSettle();
4545
return messages;
4646
}

lib/notifications/display.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class NotificationDisplayManager {
235235
// TODO(nav): Better interact with existing nav stack on notif open
236236
navigator.push(MaterialAccountWidgetRoute<void>(accountId: account.id,
237237
// TODO(#82): Open at specific message, not just conversation
238-
page: MessageListPage(narrow: narrow)));
238+
page: MessageListPage(initNarrow: narrow)));
239239
return;
240240
}
241241
}

lib/widgets/message_list.dart

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import 'text.dart';
2626
import 'theme.dart';
2727

2828
class MessageListPage extends StatefulWidget {
29-
const MessageListPage({super.key, required this.narrow});
29+
const MessageListPage({super.key, required this.initNarrow});
3030

3131
static Route<void> buildRoute({int? accountId, BuildContext? context,
3232
required Narrow narrow}) {
3333
return MaterialAccountWidgetRoute(accountId: accountId, context: context,
34-
page: MessageListPage(narrow: narrow));
34+
page: MessageListPage(initNarrow: narrow));
3535
}
3636

3737
/// A [ComposeBoxController], if this [MessageListPage] offers a compose box.
@@ -44,7 +44,7 @@ class MessageListPage extends StatefulWidget {
4444
return messageListPageState!._composeBoxKey.currentState;
4545
}
4646

47-
final Narrow narrow;
47+
final Narrow initNarrow;
4848

4949
@override
5050
State<MessageListPage> createState() => _MessageListPageState();
@@ -54,15 +54,22 @@ class MessageListPage extends StatefulWidget {
5454
const _kUnsubscribedStreamRecipientHeaderColor = Color(0xfff5f5f5);
5555

5656
class _MessageListPageState extends State<MessageListPage> {
57+
Narrow? narrow;
5758
final GlobalKey<ComposeBoxController> _composeBoxKey = GlobalKey();
5859

60+
@override
61+
void initState() {
62+
narrow = widget.initNarrow;
63+
super.initState();
64+
}
65+
5966
@override
6067
Widget build(BuildContext context) {
6168
final store = PerAccountStoreWidget.of(context);
6269

6370
final Color? appBarBackgroundColor;
6471
bool removeAppBarBottomBorder = false;
65-
switch(widget.narrow) {
72+
switch(narrow!) {
6673
case CombinedFeedNarrow():
6774
appBarBackgroundColor = null; // i.e., inherit
6875

@@ -84,7 +91,7 @@ class _MessageListPageState extends State<MessageListPage> {
8491
}
8592

8693
return Scaffold(
87-
appBar: AppBar(title: MessageListAppBarTitle(narrow: widget.narrow),
94+
appBar: AppBar(title: MessageListAppBarTitle(narrow: narrow!),
8895
backgroundColor: appBarBackgroundColor,
8996
shape: removeAppBarBottomBorder
9097
? const Border()
@@ -110,11 +117,11 @@ class _MessageListPageState extends State<MessageListPage> {
110117
// if those details get complicated, refactor to avoid copying.
111118
// TODO(#311) If we have a bottom nav, it will pad the bottom
112119
// inset, and this should always be true.
113-
removeBottom: widget.narrow is! CombinedFeedNarrow,
120+
removeBottom: narrow is! CombinedFeedNarrow,
114121

115122
child: Expanded(
116-
child: MessageList(narrow: widget.narrow))),
117-
ComposeBox(controllerKey: _composeBoxKey, narrow: widget.narrow),
123+
child: MessageList(narrow: narrow!))),
124+
ComposeBox(controllerKey: _composeBoxKey, narrow: narrow!),
118125
]))));
119126
}
120127
}

test/notifications/display_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ void main() {
275275
route.isA<MaterialAccountWidgetRoute>()
276276
..accountId.equals(account.id)
277277
..page.isA<MessageListPage>()
278-
.narrow.equals(SendableNarrow.ofMessage(message,
278+
.initNarrow.equals(SendableNarrow.ofMessage(message,
279279
selfUserId: account.userId));
280280
}
281281

test/widgets/action_sheet_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
6868
home: GlobalStoreWidget(
6969
child: PerAccountStoreWidget(
7070
accountId: eg.selfAccount.id,
71-
child: MessageListPage(narrow: narrow))))));
71+
child: MessageListPage(initNarrow: narrow))))));
7272

7373
// global store, per-account store, and message list get loaded
7474
await tester.pumpAndSettle();

test/widgets/autocomplete_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Future<Finder> setupToComposeInput(WidgetTester tester, {
5858
child: PerAccountStoreWidget(
5959
accountId: eg.selfAccount.id,
6060
child: MessageListPage(
61-
narrow: DmNarrow(
61+
initNarrow: DmNarrow(
6262
allRecipientIds: [eg.selfUser.userId, eg.otherUser.userId],
6363
selfUserId: eg.selfUser.userId,
6464
)))))));

test/widgets/content_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ void main() {
793793
await tapText(tester, find.text('stream'));
794794
check(testBinding.takeLaunchUrlCalls()).isEmpty();
795795
check(pushedRoutes).single.isA<WidgetRoute>()
796-
.page.isA<MessageListPage>().narrow.equals(const StreamNarrow(1));
796+
.page.isA<MessageListPage>().initNarrow.equals(const StreamNarrow(1));
797797
});
798798

799799
testWidgets('invalid internal links are opened in browser', (tester) async {

test/widgets/message_list_checks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import 'package:zulip/model/narrow.dart';
33
import 'package:zulip/widgets/message_list.dart';
44

55
extension MessageListPageChecks on Subject<MessageListPage> {
6-
Subject<Narrow> get narrow => has((x) => x.narrow, 'narrow');
6+
Subject<Narrow> get initNarrow => has((x) => x.initNarrow, 'initNarrow');
77
}

test/widgets/message_list_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void main() {
7676
home: GlobalStoreWidget(
7777
child: PerAccountStoreWidget(
7878
accountId: eg.selfAccount.id,
79-
child: MessageListPage(narrow: narrow))))));
79+
child: MessageListPage(initNarrow: narrow))))));
8080

8181
// global store, per-account store, and message list get loaded
8282
await tester.pumpAndSettle();

test/widgets/profile_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ void main() {
259259
await tester.tap(targetWidget);
260260
check(pushedRoutes).last.isA<WidgetRoute>().page
261261
.isA<MessageListPage>()
262-
.narrow.equals(DmNarrow.withUser(1, selfUserId: eg.selfUser.userId));
262+
.initNarrow.equals(DmNarrow.withUser(1, selfUserId: eg.selfUser.userId));
263263
});
264264

265265
testWidgets('page builds; user links render multiple avatars', (WidgetTester tester) async {

test/widgets/recent_dm_conversations_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ void main() {
328328

329329
check(pushedRoutes).last.isA<WidgetRoute>().page
330330
.isA<MessageListPage>()
331-
.narrow.equals(expectedNarrow);
331+
.initNarrow.equals(expectedNarrow);
332332
}
333333

334334
testWidgets('1:1', (WidgetTester tester) async {

0 commit comments

Comments
 (0)