当我导航到我的设置页面并刷新页面时,会出现下面图片中看到的错误。我似乎无法解决它。目前的设置如下:
在主文件中:
当我尝试刷新SettingsPage时,出现错误。我以为使用Obx有问题,但即使只返回带颜色的Container也会显示错误。
SettingsPage:
在主文件中:
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(),
),
),
];
当我尝试刷新SettingsPage时,出现错误。我以为使用Obx有问题,但即使只返回带颜色的Container也会显示错误。
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(), );
}
}