Home > Software engineering >  Flutter GetX Obx do not update UI
Flutter GetX Obx do not update UI

Time:03-10

I have a screen that I'd put all body in an Obx , I have a widget that has a parameter named activeIndex like this

AnimatedSmoothIndicator(
    activeIndex: homeController.carouselPage.value,
    count: homeController.posts[index].images.length,
    effect: WormEffect(),
  ),

carouselPage parameter give it's value in controller like this

RxInt carouselPage = 0.obs;

    SetCarouselIndex(int index) {
        carouselPage.value = index;
      }

SetCarouselIndex fires and the value changes but the UI not change . What is the problem ?

CodePudding user response:

final carouselPage = 0.obs;

// on this part actually lacking a update();
SetCarouselIndex(int? index) {
carouselPage.value = index;
update();
}

so other thing to update also like this

SetCarouselIndex(int? index) {
carouselPage(index!);
}

CodePudding user response:

    You can use 
    var carouselPage = 0.obs;

    instead of
    RxInt carouselPage = 0.obs;

    SetCarouselIndex(int index) {
      carouselPage.value = index
    }

    Obx(()=>
      AnimatedSmoothIndicator(
        activeIndex: homeController.carouselPage.value,
        count: homeController.posts[index].images.length,
        effect: WormEffect(),
    ),)
  • Related