GetPage binding not working with Navigator - GetX

28 views Asked by At

GetView is unable to find the controller i registered using Bindings in Navigator. i navigate to the GetView with Get.toNamed() and pass the route name and the Navigator ID;

Hey, i have the following setup (for illustration):

The controller:

class DetailsPageController extends GetxController {...}

The binding:

class DetailsPageBindings extends Bindings {
    @override
    void dependencies() {
        Get.put(DetailsPageController());
    }
}

The method Navigator.onGenerateRoute returns the following GetPage for route /detailsPage:

GetPage(
  name: "/detailsPage",
  page: () => const DetailsPage(),
  binding: DetailsPageBindings(),
)

The page itselft:

class DetailsPage extends GetView<DetailsPageController>() {...}

when i try to navigate to the page with Get.toNamed("/detailsPage", id:..., ), i get the following:

DetailsPageController() not found, you need to call Get.put() or Get.lazyPut()...
1

There are 1 answers

2
Jaimin Raval On

just replace your Get.put(); to Get.lazyPut(); in Bindings.

Example :

class DetailsPageBindings extends Bindings {
    @override
    void dependencies() {
        //Get.put(DetailsPageController()); remove this
        Get.lazyPut<DetailsPageController>(() => DetailsPageController());// add this line
    }
}