3

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(), ); 
      } 
}

enter image description here

Valentine
  • 161
  • 1
  • 12

1 Answers1

1

try the normal one's

class YourBind extends Binding{

  @override
  void dependencies() {
    // TODO: implement dependencies
     Get.lazyPut(() => TaskController(), fenix: true);
}

Then for the GetPage

class RouteList{

  class RouteList {
  static final routeLists = [
    GetPage(
        transition: Transition.cupertinoDialog,
        transitionDuration: 350.milliseconds,
        binding: YourBind(),
        name: "/home",
        page: () => const SettingPage()),
  ];
}

}

then for the controller

class SettingsController extends GetxController{
  final youController = Get.find<TaskController>();
 
}

next is

class SettingsPage extends GetView<SettingsController> { 
     
     final taskController = controller.youController ;

     @override Widget build(BuildContext context) { 
        return Scaffold( body: Container(), ); 
      } 
}
Arbiter Chil
  • 1,061
  • 1
  • 6
  • 9