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;
}
2
Answers
Use
RxInt
instead ofRx<int>
Consider using
RxInt
instead ofRx<int>
for better performance.Use GetxController class
Use a
GetxController
instead 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:
Ok I see is not your fault, it’s a package issue, I was checking the code https://github.com/SandroMaglione/step-progress-indicator/blob/master/lib/src/circular_step_progress_indicator.dart#L527C3-L528C72 and it’s not refreshing the custompainter because the condition is wrong.
If you want to force the widget refresh, you could use a different key and it will re-insert the widget into the widget tree.
Add this key property: