1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Flutter auto_route package Using 'keepHistory: false' and replaceAll(), initial...

Discussão em 'Mobile' iniciado por Stack, Outubro 4, 2024 às 03:12.

  1. Stack

    Stack Membro Participativo

    I am experiencing a navigation issue in a Flutter web application using the AutoRoute package. My app first loads a SplashScreen that checks if a user is authenticated. If they're not, it navigates to a LoginScreen. Once on this page, the browser's back button should be disabled as the SplashScreen should theoretically not be in the navigation stack (due to keepHistory: false).

    Below is my router configuration & Splash screen code:

    @AutoRouterConfig()
    class AppRouter extends RootStackRouter {
    @override
    List<AutoRoute> get routes => [
    AutoRoute(
    page: SplashRoute.page,
    initial: true,
    keepHistory: false,
    ),
    AutoRoute(
    page: LoginRoute.page,
    ),
    // More routes...
    ];
    }


    @RoutePage()
    class SplashScreen extends StatelessWidget {
    const SplashScreen({super.key});

    @override
    Widget build(BuildContext context) {
    final authService = Get.find<AuthService>();
    if (authService.isAuthenticated) {
    context.router.replaceAll([const HomeRoute()]);
    } else {
    context.router.replaceAll([LoginRoute()]);
    }
    return const Scaffold(body: SizedBox.expand());
    }
    }


    However, if I navigate to a page like Forgot Password or Registration, which pushes an additional route to the stack, then hit the browser's back button, it goes back to the Login page. On the Login page, the back button erroneously remains active, and hitting it navigates back to the Splash Screen.

    This happens despite the Splash Screen having keepHistory: false and using replaceAll() to push the Login route from the Splash Screen. Are there any suggestions or workarounds for this issue?

    I have searched online for the solution but no workaround is funded.

    Continue reading...

Compartilhe esta Página