Hi guys i had Rxint (completed) that change its value from the function (completedTask) that is used for calculate the completed task from the local db and save it in the Rxint (completed) the problem is the widget did't rebuild when i change the value unless i use the host reload i tried so much without any soliotion ,plz help me this is the widget:
Obx(() {
return CircularStepProgressIndicator(
totalSteps: todoDb.data?.length??1,
currentStep: todoDb.completed.value,
selectedColor: Colors.yellow,
unselectedColor: Colors.lightBlueAccent,
padding: 0,
width: 50,
height: 50,
child: const Icon(
Icons.download_done_outlined,
color: Colors.blueAccent,
size: 20,
),
);
}
);
}
and this is the used function:
class TodoDb{
Rx<int> completed=0.obs;
completedTask(bool isUpd) async {
if(isUpd==false){
await readData();
}
for (var e in data!) {
if (e['isDone'] == 1) {
completed.value = completed.value + 1;
}
}
print(completed.value);
return completed.value;
}
Use
RxIntinstead ofRx<int>Consider using
RxIntinstead ofRx<int>for better performance.Use GetxController class
Use a
GetxControllerinstead of a plain class. This provides the update method, which notifies listeners about the change.So your code should look like this:
and your widget something like this:
you also need to initialize the TodoController at a suitable place: