Skip to content

Commit bd70287

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

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
@@ -35,6 +35,12 @@ abstract class WidgetRoute<T extends Object?> extends PageRoute<T> {
3535
Widget get page;
3636
}
3737

38+
/// A page route that specifies a particular Zulip account to use, by ID.
39+
abstract class AccountRoute<T extends Object?> extends PageRoute<T> {
40+
/// The [Account.id] of the account to use for this page.
41+
int get accountId;
42+
}
43+
3844
/// A [MaterialPageRoute] that always builds the same widget.
3945
///
4046
/// This is useful for making the route more transparent for a test to inspect.
@@ -56,8 +62,10 @@ class MaterialWidgetRoute<T extends Object?> extends MaterialPageRoute<T> implem
5662
}
5763

5864
/// A mixin for providing a given account's per-account store on a page route.
59-
mixin AccountPageRouteMixin<T extends Object?> on PageRoute<T> {
65+
mixin AccountPageRouteMixin<T extends Object?> on PageRoute<T> implements AccountRoute<T> {
66+
@override
6067
int get accountId;
68+
6169
Widget? get loadingPlaceholderPage;
6270

6371
@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)