previously I only used firebase authstate (StreamBuilder) by using initialroutes for routes my page
now I want to use go_route to redirect my page if FirebaseAuth not null
how can go_routes be able to detect the state of the authstatechange
this My Main.dart class
Widget build(BuildContext context) {
return StreamBuilder<User?>(
stream: authservice.authState,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.active) {
print(snapshot.data);
return Sizer(builder: ((context, orientation, deviceType) {
return MaterialApp.router(
builder: (context, child) => ResponsiveWrapper.builder(child,
maxWidth: 1200,
minWidth: 480,
defaultScale: true,
breakpoints: [
const ResponsiveBreakpoint.resize(450, name: MOBILE),
const ResponsiveBreakpoint.autoScale(800, name: TABLET),
const ResponsiveBreakpoint.autoScale(1000, name: TABLET),
const ResponsiveBreakpoint.resize(1200, name: DESKTOP),
const ResponsiveBreakpoint.autoScale(2460, name: "4K"),
],
background: Container(color: const Color(0xFFF5F5F5))),
title: 'Welcome',
theme: ThemeData(primaryColor: Colors.blueGrey),
// initialRoute: snapshot.data != null ? "/dashboard" : "/intro",
// routes: {
// '/': (context) => const Intro(),
// '/dashboard': (context) => const Dashboard(),
// '/login': (context) => const Login(),
// '/register': (context) => const Register()
// },
routerConfig: router,
);
}));
}
return const Loading();
});
}
this my go_route class
final GoRouter router = GoRouter(
routes: routes,
initialLocation: '/login',
debugLogDiagnostics: true,
routerNeglect: true);
List<RouteBase> routes = [
GoRoute(
path: '/login',
name: 'login',
builder: (context, state) => const Login(),
),
GoRoute(
path: '/register',
name: 'register',
builder: (context, state) => const Register(),
),
GoRoute(
path: '/intro',
name: 'intro',
builder: (context, state) => const Intro(),
),
GoRoute(
path: '/dashboard',
name: 'dashboard',
builder: (context, state) => const Dashboard(),
),
];
in my authservice class I just use
final FirebaseAuth _auth = FirebaseAuth.instance;
Stream<User?> get authState => _auth.authStateChanges();
how can go_routes be able to detect the state of the authstatechange, in some sample projects no one is using go_routes with authstatechange from Firebase