Skip to content

Commit 838d5a7

Browse files
PIG208gnprice
authored andcommitted
msglist [nfc]: Make narrow mutable for _MessageListPageState.
This allows us to switch narrow when a move happens. Signed-off-by: Zixuan James Li <[email protected]>
1 parent a8fc00d commit 838d5a7

11 files changed

+25
-19
lines changed

integration_test/unreadmarker_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void main() {
3232
newestResult(foundOldest: true, messages: messages).toJson());
3333

3434
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
35-
child: const MessageListPage(narrow: CombinedFeedNarrow())));
35+
child: const MessageListPage(initNarrow: CombinedFeedNarrow())));
3636
await tester.pumpAndSettle();
3737
return messages;
3838
}

lib/notifications/display.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class NotificationDisplayManager {
272272
// TODO(nav): Better interact with existing nav stack on notif open
273273
navigator.push(MaterialAccountWidgetRoute<void>(accountId: account.id,
274274
// TODO(#82): Open at specific message, not just conversation
275-
page: MessageListPage(narrow: narrow)));
275+
page: MessageListPage(initNarrow: narrow)));
276276
return;
277277
}
278278

lib/widgets/message_list.dart

+15-9
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ abstract class MessageListPageState {
191191
}
192192

193193
class MessageListPage extends StatefulWidget {
194-
const MessageListPage({super.key, required this.narrow});
194+
const MessageListPage({super.key, required this.initNarrow});
195195

196196
static Route<void> buildRoute({int? accountId, BuildContext? context,
197197
required Narrow narrow}) {
198198
return MaterialAccountWidgetRoute(accountId: accountId, context: context,
199-
page: MessageListPage(narrow: narrow));
199+
page: MessageListPage(initNarrow: narrow));
200200
}
201201

202202
/// The [MessageListPageState] above this context in the tree.
@@ -211,29 +211,35 @@ class MessageListPage extends StatefulWidget {
211211
return state!;
212212
}
213213

214-
final Narrow narrow;
214+
final Narrow initNarrow;
215215

216216
@override
217217
State<MessageListPage> createState() => _MessageListPageState();
218218
}
219219

220220
class _MessageListPageState extends State<MessageListPage> implements MessageListPageState {
221221
@override
222-
Narrow get narrow => widget.narrow;
222+
late Narrow narrow;
223223

224224
@override
225225
ComposeBoxController? get composeBoxController => _composeBoxKey.currentState;
226226

227227
final GlobalKey<ComposeBoxController> _composeBoxKey = GlobalKey();
228228

229+
@override
230+
void initState() {
231+
super.initState();
232+
narrow = widget.initNarrow;
233+
}
234+
229235
@override
230236
Widget build(BuildContext context) {
231237
final store = PerAccountStoreWidget.of(context);
232238
final messageListTheme = MessageListTheme.of(context);
233239

234240
final Color? appBarBackgroundColor;
235241
bool removeAppBarBottomBorder = false;
236-
switch(widget.narrow) {
242+
switch(narrow) {
237243
case CombinedFeedNarrow():
238244
case MentionsNarrow():
239245
appBarBackgroundColor = null; // i.e., inherit
@@ -256,7 +262,7 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
256262
}
257263

258264
return Scaffold(
259-
appBar: AppBar(title: MessageListAppBarTitle(narrow: widget.narrow),
265+
appBar: AppBar(title: MessageListAppBarTitle(narrow: narrow),
260266
backgroundColor: appBarBackgroundColor,
261267
shape: removeAppBarBottomBorder
262268
? const Border()
@@ -280,11 +286,11 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
280286
// The compose box, when present, pads the bottom inset.
281287
// TODO(#311) If we have a bottom nav, it will pad the bottom
282288
// inset, and this should always be true.
283-
removeBottom: ComposeBox.hasComposeBox(widget.narrow),
289+
removeBottom: ComposeBox.hasComposeBox(narrow),
284290

285291
child: Expanded(
286-
child: MessageList(narrow: widget.narrow))),
287-
ComposeBox(controllerKey: _composeBoxKey, narrow: widget.narrow),
292+
child: MessageList(narrow: narrow))),
293+
ComposeBox(controllerKey: _composeBoxKey, narrow: narrow),
288294
]))));
289295
}
290296
}

test/notifications/display_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ void main() {
546546
route.isA<MaterialAccountWidgetRoute>()
547547
..accountId.equals(account.id)
548548
..page.isA<MessageListPage>()
549-
.narrow.equals(SendableNarrow.ofMessage(message,
549+
.initNarrow.equals(SendableNarrow.ofMessage(message,
550550
selfUserId: account.userId));
551551
}
552552

test/widgets/action_sheet_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
5959
).toJson());
6060

6161
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
62-
child: MessageListPage(narrow: narrow)));
62+
child: MessageListPage(initNarrow: narrow)));
6363

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

test/widgets/autocomplete_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Future<Finder> setupToComposeInput(WidgetTester tester, {
4848
prepareBoringImageHttpClient();
4949

5050
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
51-
child: MessageListPage(narrow: DmNarrow(
51+
child: MessageListPage(initNarrow: DmNarrow(
5252
allRecipientIds: [eg.selfUser.userId, eg.otherUser.userId],
5353
selfUserId: eg.selfUser.userId))));
5454

test/widgets/content_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ void main() {
815815
await tapText(tester, find.text('stream'));
816816
check(testBinding.takeLaunchUrlCalls()).isEmpty();
817817
check(pushedRoutes).single.isA<WidgetRoute>()
818-
.page.isA<MessageListPage>().narrow.equals(const ChannelNarrow(1));
818+
.page.isA<MessageListPage>().initNarrow.equals(const ChannelNarrow(1));
819819
});
820820

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

test/widgets/message_list_checks.dart

+1-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void main() {
6969
newestResult(foundOldest: foundOldest, messages: messages).toJson());
7070

7171
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
72-
child: MessageListPage(narrow: narrow)));
72+
child: MessageListPage(initNarrow: narrow)));
7373

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

test/widgets/profile_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ void main() {
253253
await tester.tap(targetWidget);
254254
check(pushedRoutes).last.isA<WidgetRoute>().page
255255
.isA<MessageListPage>()
256-
.narrow.equals(DmNarrow.withUser(1, selfUserId: eg.selfUser.userId));
256+
.initNarrow.equals(DmNarrow.withUser(1, selfUserId: eg.selfUser.userId));
257257
});
258258

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

test/widgets/recent_dm_conversations_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ void main() {
322322

323323
check(pushedRoutes).last.isA<WidgetRoute>().page
324324
.isA<MessageListPage>()
325-
.narrow.equals(expectedNarrow);
325+
.initNarrow.equals(expectedNarrow);
326326
}
327327

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

0 commit comments

Comments
 (0)