You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi guys!
I'm using deferred loading for my web app to load my screens. The problem is that, although it's correctly partitioned into files, it's loading everything at once.
Here for example I'm on the log in page and you can see how all the screens are already loaded:
I think it can may be because of my AppRouter configuration or my Auth Guards that needs all the pages to configure.
All my RoutePages have the deferredLoading = true even my AppRouter.
Here it is:
@AutoRouterConfig(replaceInRouteName: 'Screen,Route', deferredLoading: true)
class AppRouter extends RootStackRouter {
var isAccountSetup = false;
final SessionController _sessionController = getIt.get<SessionController>();
@override
RouteType get defaultRouteType => const RouteType.material();
@override
List<AutoRoute> get routes => [
AutoRoute(
path: '/signin',
page: LogInRoute.page,
),
AutoRoute(
page: SetupRoute.page,
),
AutoRoute(
path: '/profiles',
page: ProfilesRoute.page,
),
AutoRoute(
path: '/error',
page: NoPaymentRoute.page,
),
AutoRoute(
path: '/payment',
page: PaymentRoute.page,
),
AutoRoute(
path: '/download/result',
page: DownloadResultRoute.page,
),
AutoRoute(
path: '/',
page: BaseView.page,
initial: true,
children: [
AutoRoute(
path: 'home',
page: DashboardRoute.page,
initial: true,
),
AutoRoute(
path: 'panel',
page: WorkPanelRoute.page,
),
AutoRoute(
path: 'quote',
page: QuoteRoute.page,
),
AutoRoute(
path: 'orders',
page: OrdersTableRoute.page,
),
AutoRoute(
path: 'orders/:id',
page: OrderDetailRoute.page,
),
AutoRoute(
path: 'closure',
page: ClosureRoute.page,
children: [
AutoRoute(
page: ClosureDetailComponent.page,
)
],
),
AutoRoute(
path: 'expenses',
page: ExpensesRoute.page,
),
AutoRoute(
path: 'elements/:type',
page: TestsRoute.page,
),
AutoRoute(
path: 'edit-elements',
page: EditTestRoute.page,
),
AutoRoute(
path: 'groups',
page: GroupsRoute.page,
children: [
AutoRoute(
path: '',
page: GroupsTableRoute.page,
initial: true,
),
AutoRoute(
path: 'edit-group/:groupId',
page: GroupRoute.page,
),
],
),
AutoRoute(
path: 'cultivations',
page: CultivationsRoute.page,
children: [
AutoRoute(
path: '',
page: CultivationsTableRoute.page,
initial: true,
),
AutoRoute(
page: CultivationDetailRoute.page,
),
],
),
AutoRoute(
path: 'packages',
page: PackagesRoute.page,
children: [
AutoRoute(
path: '',
page: PackagesTableRoute.page,
initial: true,
),
AutoRoute(
path: 'detail/:packageId',
page: PackageDetailRoute.page,
),
],
),
AutoRoute(
path: 'prices',
page: PriceListsRoute.page,
children: [
AutoRoute(
path: '',
initial: true,
page: PriceListsTableRoute.page,
),
AutoRoute(
path: 'detail',
page: PriceListDetailRoute.page,
),
],
),
AutoRoute(
path: 'worksheet',
page: WorksheetRoute.page,
children: [
AutoRoute(
path: 'table',
page: WorksheetTableComponent.page,
initial: true,
),
AutoRoute(
path: 'capture-result/:resultId',
page: CaptureResultRoute.page,
),
],
),
AutoRoute(
path: 'catalogs',
page: CatalogsRoute.page,
),
AutoRoute(
path: 'stock',
page: InventoryRoute.page,
children: [
AutoRoute(
path: '',
page: InventoryListRoute.page,
initial: true,
),
AutoRoute(
path: 'detail',
page: InventoryItemDetail.page,
),
],
),
AutoRoute(
path: 'patients',
page: PatientsRoute.page,
children: [
AutoRoute(
path: '',
page: PatientsTableRoute.page,
initial: true,
),
AutoRoute(
path: 'detail/:id/:name',
page: PatientDetailRoute.page,
),
],
),
AutoRoute(
path: 'users',
page: ProfilesTableRoute.page,
),
AutoRoute(
path: 'user-detail',
page: ProfileDetailRoute.page,
),
AutoRoute(
path: 'doctors',
page: DoctorsTableRoute.page,
),
AutoRoute(
path: 'doctor-detail',
page: DoctorsDetailRoute.page,
),
AutoRoute(
path: 'configuration',
page: ConfigRoute.page,
),
],
),
];
@override
late final List<AutoRouteGuard> guards = [
AutoRouteGuard.simple((resolver, router) async {
if (resolver.routeName == DownloadResultRoute.name) {
resolver.next();
return;
}
final isAuthenticated = FirebaseAuth.instance.currentUser != null;
if (!isAuthenticated && resolver.routeName == LogInRoute.name) {
resolver.next();
return;
}
// if user is not authenticated and try to access any other page
// we redirect the user to the login page.
if (!isAuthenticated && resolver.route.name != LogInRoute.name) {
resolver.redirect(
LogInRoute(),
);
return;
}
// if the user is authenticated and try to acces login page
// we abort the navigation.
if (isAuthenticated && resolver.route.name == LogInRoute.name) {
if (resolver.pendingRoutes.isEmpty) {
router.navigate(const DashboardRoute());
return;
}
resolver.next(false);
return;
}
// if the user is authenticated and try to acces any other page
if (isAuthenticated && resolver.route.name != LogInRoute.name) {
final hasAccess = await _sessionController.hasAccess;
// If the user doesn't have access (it has not payed)
if (!hasAccess) {
if (resolver.route.name == PaymentRoute.name) {
resolver.next();
return;
}
if (resolver.route.name != NoPaymentRoute.name) {
resolver.redirect(const NoPaymentRoute());
return;
}
resolver.next();
}
if (hasAccess && resolver.route.name == NoPaymentRoute.name ||
resolver.route.name == PaymentRoute.name) {
router.navigate(const DashboardRoute());
return;
}
if (hasAccess && resolver.route.name != NoPaymentRoute.name) {
if (!isAccountSetup) {
final snapshot = await FirebaseFirestore.instance
.collection('laboratories')
.doc(FirebaseAuth.instance.currentUser?.uid)
.get();
final accountConfiguration = snapshot.data();
isAccountSetup = switch (accountConfiguration) {
{'setup': bool setup} => setup,
_ => false,
};
}
if (isAccountSetup) {
if (resolver.route.name == SetupRoute.name) {
if (resolver.pendingRoutes.isEmpty) {
router.navigateNamed('/home');
} else {
resolver.next(false);
}
} else {
if (ProfileController.instance.user != null) {
if (resolver.route.name == ProfilesRoute.name) {
router.navigateNamed('/home');
} else {
resolver.next();
}
} else {
if (resolver.route.name == ProfilesRoute.name) {
resolver.next();
} else {
resolver.redirect(
ProfilesRoute(
onResult: (didLogin) => resolver.next(didLogin),
),
);
}
}
}
}
if (!isAccountSetup && resolver.routeName == SetupRoute.name) {
resolver.next();
}
if (!isAccountSetup && resolver.routeName != SetupRoute.name) {
resolver.redirect(
SetupRoute(
onResult: (success) {
resolver.next(success);
},
),
);
}
}
}
}),
];
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi guys!
I'm using deferred loading for my web app to load my screens. The problem is that, although it's correctly partitioned into files, it's loading everything at once.
Here for example I'm on the log in page and you can see how all the screens are already loaded:
I think it can may be because of my AppRouter configuration or my Auth Guards that needs all the pages to configure.
All my RoutePages have the deferredLoading = true even my AppRouter.
Here it is:
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions