Skip to content

Commit d11b519

Browse files
gnpricerajveermalviya
authored andcommitted
page [nfc]: Add interface to get account ID for most of our routes
1 parent e263d1d commit d11b519

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

lib/widgets/home.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ enum _HomePageTab {
3131
class HomePage extends StatefulWidget {
3232
const HomePage({super.key});
3333

34-
static Route<void> buildRoute({required int accountId}) {
34+
static AccountRoute<void> buildRoute({required int accountId}) {
3535
return MaterialAccountWidgetRoute(accountId: accountId,
3636
loadingPlaceholderPage: _LoadingPlaceholderPage(accountId: accountId),
3737
page: const HomePage());

lib/widgets/message_list.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ abstract class MessageListPageState {
188188
class MessageListPage extends StatefulWidget {
189189
const MessageListPage({super.key, required this.initNarrow});
190190

191-
static Route<void> buildRoute({int? accountId, BuildContext? context,
191+
static AccountRoute<void> buildRoute({int? accountId, BuildContext? context,
192192
required Narrow narrow}) {
193193
return MaterialAccountWidgetRoute(accountId: accountId, context: context,
194194
page: MessageListPage(initNarrow: narrow));

lib/widgets/page.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ abstract class WidgetRoute<T extends Object?> extends PageRoute<T> {
1111
Widget get page;
1212
}
1313

14+
/// A page route that specifies a particular Zulip account to use, by ID.
15+
abstract class AccountRoute<T extends Object?> extends PageRoute<T> {
16+
/// The [Account.id] of the account to use for this page.
17+
int get accountId;
18+
}
19+
1420
/// A [MaterialPageRoute] that always builds the same widget.
1521
///
1622
/// This is useful for making the route more transparent for a test to inspect.
@@ -32,8 +38,10 @@ class MaterialWidgetRoute<T extends Object?> extends MaterialPageRoute<T> implem
3238
}
3339

3440
/// A mixin for providing a given account's per-account store on a page route.
35-
mixin AccountPageRouteMixin<T extends Object?> on PageRoute<T> {
41+
mixin AccountPageRouteMixin<T extends Object?> on PageRoute<T> implements AccountRoute<T> {
42+
@override
3643
int get accountId;
44+
3745
Widget? get loadingPlaceholderPage;
3846

3947
@override

lib/widgets/profile.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ProfilePage extends StatelessWidget {
3030

3131
final int userId;
3232

33-
static Route<void> buildRoute({int? accountId, BuildContext? context,
33+
static AccountRoute<void> buildRoute({int? accountId, BuildContext? context,
3434
required int userId}) {
3535
return MaterialAccountWidgetRoute(accountId: accountId, context: context,
3636
page: ProfilePage(userId: userId));

test/widgets/page_checks.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ extension WidgetRouteChecks<T> on Subject<WidgetRoute<T>> {
66
Subject<Widget> get page => has((x) => x.page, 'page');
77
}
88

9-
extension AccountPageRouteMixinChecks<T> on Subject<AccountPageRouteMixin<T>> {
9+
extension AccountRouteChecks<T> on Subject<AccountRoute<T>> {
1010
Subject<int> get accountId => has((x) => x.accountId, 'accountId');
1111
}

0 commit comments

Comments
 (0)