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
Here is my code using declarative routing in order to track the Authentication state of the user withing my app:
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:test/helpers/observer.dart';
import 'package:test/services/auth.dart';
import 'helpers/app_router.dart';
import 'helpers/app_router.gr.dart';
final AuthService authService = AuthService();
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await dotenv.load();
await authService.setupAuth();
runApp(const App());
}
class App extends StatefulWidget {
const App({super.key});
@override
State<App> createState() => _AppState();
}
class _AppState extends State<App> {
final _appRouter = AppRouter();
bool splashFinished=false;
@override
void initState() {
super.initState();
authService.addListener(() => setState(() {}));
}
@override
void dispose() {
authService.removeListener(() { });
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Test',
builder: EasyLoading.init(),
routerDelegate: AutoRouterDelegate.declarative(
_appRouter,
navigatorObservers: () => [MyObserver()],
routes: (_) => [
if (splashFinished==false)
SplashRoute(onResult: _splashFinished)
else if (splashFinished==true && authService.isSignedIn)
// if the user is logged in, they may proceed to the main App
TabRouter(authService: authService)
else
// if they are not logged in, bring them to the Login page
AuthRouter(authService: authService),
],
),
routeInformationParser:
_appRouter.defaultRouteParser(includePrefixMatches: true),
);
}
void _splashFinished(bool isFinished) {
setState(() {
splashFinished = isFinished;
});
}
}
As you can see, I'm also using a Splash screen in the logic of the app. This is what it messed with my example. If I remove the splash screen it works perfectly.
I see from the stack that something with rebuilding is happening. But it doesn't make sense to me at least. authService.setupAuth() is way before that. Also the callback
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
-
Hello there,
Here is my code using declarative routing in order to track the Authentication state of the user withing my app:
As you can see, I'm also using a Splash screen in the logic of the app. This is what it messed with my example. If I remove the splash screen it works perfectly.
The above example produces this error:
I see from the stack that something with rebuilding is happening. But it doesn't make sense to me at least.
authService.setupAuth()
is way before that. Also the callbackis only being called in the
SplashRoute
after the animation is being done.Any help here? Am I missing something?
Beta Was this translation helpful? Give feedback.
All reactions