Search code examples
flutterflutter-getx

Flutter GetX call fetch data only once in the build methode


I have a method called getData() which used to load data from API, and i am displaying data in a separate screen, I have one issue which whenever I navigate to this page it rebuild the whole screen and call the API again and again. PS: I'm using getX Obx to control the UI Question: how to call the function only when new data has added


Solution

  • class CategoryPageBinding extends Bindings {
      @override
      void dependencies() {
        Get.put(CategoryPageController(), permanent: true);
      }
    }
     
    
    class CategoryPageController extends GetxController {
      @override
      void onInit() {
        super.onInit();
        getAllCategories();
      }
    }