'I need a way to have screens on the stack without showing them. I've already tried a few packages but haven't found what I need

I need a page to be pushed from main when the app is started but other pages to be in the stack behind this one. I have already tried using the auto_route and go_router packages under the advice of a user but unfortunately this is not what I am looking for. These allowed me to push multiple screens but failed to work with the classic Navigator.

Route routeMapper(segment) {
  print('routeMapper, segment: $segment');
  final routes = {
    'FirstPage': MaterialPageRoute(builder: (_) => const FirstPage()),
    'SignInEmail':
        MaterialPageRoute(builder: (_) => const InserisciEmailPage()),
    'VerificaEmail':
        MaterialPageRoute(builder: (_) => const VerificaEmailPage()),
    'SignInDati': MaterialPageRoute(builder: (_) => const InserisciDatiPage()),
    'SignInNumero':
        MaterialPageRoute(builder: (_) => const InserisciNumeroPage()),
    'Home': MaterialPageRoute(builder: (_) => const HomePage()),
  };
  return routes[segment]!;
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Reminday',
      supportedLocales: const [
        Locale('it', ''),
      ],
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      scrollBehavior: NoGlowBehaviour(),
      theme: ThemeData(
        // primaryColor: const Color(0xFF723EAC),
        // bodyColor: testo,
        textTheme: const TextTheme(
          bodyText1: TextStyle(),
          bodyText2: TextStyle(),
        ).apply(bodyColor: testo, displayColor: testo),
        textSelectionTheme: const TextSelectionThemeData(
          cursorColor: pulsante,
          selectionColor: pulsante,
          selectionHandleColor: pulsante,
        ),
      ),
      // onGenerateRoute: RouteGenerator.generateRoute,

      initialRoute: FirebaseAuth.instance.currentUser == null
          ? "FirstPage/SignInEmail/SignInDati"
          : FirebaseAuth.instance.currentUser!.providerData.length == 1
              ? FirebaseAuth.instance.currentUser!.emailVerified == false
                  ? "/SignInVerificaEmail"
                  : FirebaseAuth.instance.currentUser!.displayName == null
                      ? "/SignInDati"
                      : "/SignInNumero"
              : "Home",
      onGenerateInitialRoutes: (initialRoute) =>
          initialRoute.split('/').map(routeMapper).toList(),
      debugShowCheckedModeBanner: false, //TODO rimuovere prima di confezionare
    );
  }
}

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source