Skip to content

Commit

Permalink
nav [nfc]: Support custom loading page with AccountPageRouteMixin
Browse files Browse the repository at this point in the history
This preps for adding a special loading page for the home page.

Signed-off-by: Zixuan James Li <[email protected]>
  • Loading branch information
PIG208 committed Dec 7, 2024
1 parent fb543fc commit 921fbab
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/widgets/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ class MaterialWidgetRoute<T extends Object?> extends MaterialPageRoute<T> implem
/// A mixin for providing a given account's per-account store on a page route.
mixin AccountPageRouteMixin<T extends Object?> on PageRoute<T> {
int get accountId;
Widget? get loadingPlaceholderPage;

@override
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
return PerAccountStoreWidget(
accountId: accountId,
placeholder: const LoadingPlaceholderPage(),
placeholder: loadingPlaceholderPage ?? const LoadingPlaceholderPage(),
routeToRemoveOnLogout: this,
child: super.buildPage(context, animation, secondaryAnimation));
}
Expand Down Expand Up @@ -67,6 +68,7 @@ class MaterialAccountPageRoute<T extends Object?> extends MaterialPageRoute<T> w
MaterialAccountPageRoute({
int? accountId,
BuildContext? context,
this.loadingPlaceholderPage,
required super.builder,
super.settings,
super.maintainState,
Expand All @@ -78,6 +80,9 @@ class MaterialAccountPageRoute<T extends Object?> extends MaterialPageRoute<T> w

@override
final int accountId;

@override
final Widget? loadingPlaceholderPage;
}

/// A [MaterialPageRoute] that provides a per-account store for a given account
Expand Down Expand Up @@ -105,6 +110,7 @@ class MaterialAccountWidgetRoute<T extends Object?> extends MaterialAccountPageR
MaterialAccountWidgetRoute({
super.accountId,
super.context,
super.loadingPlaceholderPage,
required this.page,
super.settings,
super.maintainState,
Expand Down Expand Up @@ -134,6 +140,7 @@ class AccountPageRouteBuilder<T extends Object?> extends PageRouteBuilder<T> wit
AccountPageRouteBuilder({
int? accountId,
BuildContext? context,
this.loadingPlaceholderPage,
super.settings,
required super.pageBuilder,
super.transitionsBuilder,
Expand All @@ -152,6 +159,9 @@ class AccountPageRouteBuilder<T extends Object?> extends PageRouteBuilder<T> wit

@override
final int accountId;

@override
Widget? loadingPlaceholderPage;
}

class LoadingPlaceholderPage extends StatelessWidget {
Expand Down

0 comments on commit 921fbab

Please sign in to comment.