传递参数而不在 flutter web 应用程序中显示 url
Pass parameter without showing in flutter web app url
我正在使用 fluro router 在 flutter web 应用程序中导航。但是我面临的问题是我想将参数传递给另一个页面而不在 url 中显示它。我该怎么做?
Main.dart代码:-
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,
);
}
}
如您所见,我可以轻松地将 abc
传递给页面传递,但我如何传递不应该在 url 中显示的第二个参数 178
?
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);
}
}
如果有人想传递参数,那么他们需要将路由函数编辑为:-
static void navigateToPage({required String routeName,required BuildContext context, int? val}) {
router.navigateTo(context, routeName, transition: TransitionType.none,routeSettings: RouteSettings(arguments: val));
}
以及导航:-
FluroRouting.navigateToPage(routeName: '/dress/abc', context: context, val: 178);
我正在使用 fluro router 在 flutter web 应用程序中导航。但是我面临的问题是我想将参数传递给另一个页面而不在 url 中显示它。我该怎么做?
Main.dart代码:-
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,
);
}
}
如您所见,我可以轻松地将 abc
传递给页面传递,但我如何传递不应该在 url 中显示的第二个参数 178
?
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);
}
}
如果有人想传递参数,那么他们需要将路由函数编辑为:-
static void navigateToPage({required String routeName,required BuildContext context, int? val}) {
router.navigateTo(context, routeName, transition: TransitionType.none,routeSettings: RouteSettings(arguments: val));
}
以及导航:-
FluroRouting.navigateToPage(routeName: '/dress/abc', context: context, val: 178);