Search code examples
flutterflutter-webflutter-navigation

Pass parameter without showing in flutter web app url


I am using fluro router to navigate in flutter web app. But the problem am facing is that i want to pass argument to another page without showing it in url. How can i do so?

Main.dart code:-

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Testing',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        fontFamily: Themes.primaryFontFamily,
      ),
      debugShowCheckedModeBanner: false,
      initialRoute: '/pass/abc',
      onGenerateRoute: FluroRouting.router.generator,
    );
  }
}

As you can see i can easily pass abc to page pass but how can i pass a second argument 178 which should not be shown in url?

class FluroRouting {
  static final router = FluroRouter();
  static Handler _passHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, dynamic> params) =>
          Pass(Argument1:params['arg'][0],Argument2: ,));//how can i get 2nd argument?

  static void setupRouter() {
    router.define('/pass/:arg', handler: _passHandler,);
    router.notFoundHandler = Handler(
        handlerFunc: (BuildContext? context, Map<String, dynamic> params) =>NotFound()
    );
  }
  static void navigateToPage({required String routeName,required BuildContext context}) {
    router.navigateTo(context, routeName, transition: TransitionType.none);
  }
}

Solution

  • In case someone wants to pass the argument then they need to edit the route function as:-

    static void navigateToPage({required String routeName,required BuildContext context, int? val}) {
        router.navigateTo(context, routeName, transition: TransitionType.none,routeSettings: RouteSettings(arguments: val));
      }
    

    and for navigating:-

    FluroRouting.navigateToPage(routeName: '/dress/abc', context: context, val: 178);