未找到 GetX Controller,需要调用 Get.put 或 Get.lazyPut
当我导航到 SettingsPage 并刷新页面时,它会抛出下图中所示的错误。我似乎不知道如何解决它。设置(到目前为止):
在main文件中:
Future<void> main() async {
Get.put(UserService(httpClient), permanent: true);
Get.put(ProjectService(httpClient), permanent: true);
Get.put(TaskService(httpClient), permanent: true);
runApp(MyApp());
}
然后:
class MyAppextends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
initialBinding: BindingsBuilder<AuthController>.put(
() => AuthController(),
permanent: true,
),
debugShowCheckedModeBanner: false,
initialRoute: BoardPage.route,
getPages: pages,
defaultTransition: Transition.fadeIn,
);
}
}
pages是我的全局绑定文件,它在我的GetMaterialApp中初始化
final List<GetPage<dynamic>> pages = <GetPage<dynamic>>[
GetPage<dynamic>(
name: OnBoardingPage.route,
page: () => OnBoardingPage(),
),
GetPage<dynamic>(
name: RegisterPage.route,
page: () => RegisterPage(),
binding: BindingsBuilder<RegisterController>.put(
() => RegisterController(),
),
),
GetPage<dynamic>(
name: LoginPage.route,
page: () => LoginPage(),
binding: BindingsBuilder<LoginController>.put(
() => LoginController(),
),
),
GetPage<dynamic>(
name: BoardPage.route,
page: () => BoardPage(),
bindings: <Bindings>[
BindingsBuilder<TaskController>.put(() => TaskController()),
BindingsBuilder<BoardController>.put(() => BoardController()),
],
),
GetPage<dynamic>(
name: SettingsPage.route,
page: () => SettingsPage(),
bindings: <Bindings>[
// TODO(dakr): remove for release
BindingsBuilder<BoardController>.put(() => BoardController()),
BindingsBuilder<SettingsController>.put(() => SettingsController()),
BindingsBuilder<TaskController>.put(() => TaskController()),
],
),
GetPage<dynamic>(
name: ProfilePage.route,
page: () => ProfilePage(),
binding: BindingsBuilder<ProfileController>.put(
() => ProfileController(),
),
),
];
,出现错误当我尝试刷新设置页面时。我认为使用 Obx 存在问题,但即使我只返回彩色容器,它也会显示错误。
设置页面:
class SettingsPage extends GetView<SettingsController> {
static const String route = '/board/settings';
final BoardController _boardController = Get.find();
final ProjectService _projectService = Get.find();
final AuthController _authController = Get.find();
@override Widget build(BuildContext context) {
return Scaffold( body: Container(), );
}
}
When I navigate to my SettingsPage and refresh the page it throws the error seen in the image below. I cant seem to figure out how to solve it. The setup (so far):
In the main file:
Future<void> main() async {
Get.put(UserService(httpClient), permanent: true);
Get.put(ProjectService(httpClient), permanent: true);
Get.put(TaskService(httpClient), permanent: true);
runApp(MyApp());
}
Then:
class MyAppextends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
initialBinding: BindingsBuilder<AuthController>.put(
() => AuthController(),
permanent: true,
),
debugShowCheckedModeBanner: false,
initialRoute: BoardPage.route,
getPages: pages,
defaultTransition: Transition.fadeIn,
);
}
}
pages is my global bindings file which is initialized in my GetMaterialApp
final List<GetPage<dynamic>> pages = <GetPage<dynamic>>[
GetPage<dynamic>(
name: OnBoardingPage.route,
page: () => OnBoardingPage(),
),
GetPage<dynamic>(
name: RegisterPage.route,
page: () => RegisterPage(),
binding: BindingsBuilder<RegisterController>.put(
() => RegisterController(),
),
),
GetPage<dynamic>(
name: LoginPage.route,
page: () => LoginPage(),
binding: BindingsBuilder<LoginController>.put(
() => LoginController(),
),
),
GetPage<dynamic>(
name: BoardPage.route,
page: () => BoardPage(),
bindings: <Bindings>[
BindingsBuilder<TaskController>.put(() => TaskController()),
BindingsBuilder<BoardController>.put(() => BoardController()),
],
),
GetPage<dynamic>(
name: SettingsPage.route,
page: () => SettingsPage(),
bindings: <Bindings>[
// TODO(dakr): remove for release
BindingsBuilder<BoardController>.put(() => BoardController()),
BindingsBuilder<SettingsController>.put(() => SettingsController()),
BindingsBuilder<TaskController>.put(() => TaskController()),
],
),
GetPage<dynamic>(
name: ProfilePage.route,
page: () => ProfilePage(),
binding: BindingsBuilder<ProfileController>.put(
() => ProfileController(),
),
),
];
The error appears when I try to refresh the SettingsPage. I thought that there was a problem using Obx but even when I only return a colored Container it shows the error.
SettingsPage:
class SettingsPage extends GetView<SettingsController> {
static const String route = '/board/settings';
final BoardController _boardController = Get.find();
final ProjectService _projectService = Get.find();
final AuthController _authController = Get.find();
@override Widget build(BuildContext context) {
return Scaffold( body: Container(), );
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试正常的
then 对于 GetPage
}
then 对于控制器
来说下一个是
try the normal one's
Then for the GetPage
}
then for the controller
next is