gpt4 book ai didi

flutter - GetX Get.arguments 总是返回 null

转载 作者:行者123 更新时间:2023-12-05 08:03:52 26 4
gpt4 key购买 nike

我有路由问题。我正在使用 GetX 并且 Get.arguments 总是返回 null。我在 route_generator.dart 中定义我的路线

class RouteGenerator {
static Route<dynamic> generateRoute(RouteSettings settings) {
switch (settings.name) {
case AppRoutes.splashScreen:
return GetPageRoute(
page: () => const SplashPage(),
binding: SplashBinding(),
transition: Transition.fade,
);
case AppRoutes.unauthenticated:
return GetPageRoute(
page: () => const UnauthenticatedPage(),
binding: UnauthenticatedBinding(),
transition: Transition.fade,
);
case AppRoutes.login:
return GetPageRoute(
page: () => const LoginPage(),
binding: LoginBinding(),
transition: Transition.fade,
);
case AppRoutes.register:
return GetPageRoute(
page: () => const RegisterPage(),
binding: RegisterBinding(),
transition: Transition.fade,
);
case AppRoutes.dashboard:
return GetPageRoute(
page: () => DashboardPage(0),
binding: DashboardBinding(),
transition: Transition.fade,
);
case AppRoutes.editProfile:
return GetPageRoute(
page: () => const EditProfilePage(),
binding: EditProfileBinding(),
transition: Transition.rightToLeft,
);
default:
return GetPageRoute(
page: () => const SplashPage(),
binding: SplashBinding(),
transition: Transition.fade,
);
}
}
}

这是我的 main.dart,我在其中指定路线

  @override
Widget build(BuildContext context) {
return GetMaterialApp(
debugShowCheckedModeBanner: false,
title: 'Test App',
defaultTransition: Transition.rightToLeft,
themeMode: ThemeMode.system,
darkTheme: Themes.darkTheme,
theme: Themes.lightTheme,
initialRoute: AppRoutes.splashScreen,
onGenerateRoute: RouteGenerator.generateRoute,
);
}

然后当我尝试使用它正常工作的路由启动新屏幕时,我无法检索参数,因为它们为空

list_view.dart

onTap: () => {
Get.toNamed(AppRoutes.exerciseDetail, arguments: [
{'exercise': exercise}
])
},

打印返回空detail_view_controller.dart

  @override
void onInit() {
dynamic arguments = Get.arguments;
print(arguments);
super.onInit();
}

感谢任何帮助或建议,谢谢:)

最佳答案

尝试使用 out [ ] 传递参数。比如这些参数:{'exercise': exercise}

你也可以这样尝试:

arguments:{'exercise': exercise, 'name':max}

并且可以访问它们:

Print(Get.arguments['name']);
// output max

关于flutter - GetX Get.arguments 总是返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71130072/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com