Skip to content

Instantly share code, notes, and snippets.

@quangpd
Created August 1, 2023 00:10
Show Gist options
  • Save quangpd/737eef46ffe6b61fb8c902f8a6e698b3 to your computer and use it in GitHub Desktop.
Save quangpd/737eef46ffe6b61fb8c902f8a6e698b3 to your computer and use it in GitHub Desktop.
await Future.delayed(Duration.zero); // prevent setState() or markNeedsBuild() error with Getx
This is because you are trying to update an observable value while the widget tree is getting built, this is probably caused because of the method
GetBuilder<CustomerServiceController>(
init: CustomerServiceController(),
initState: (state) async { // Here
await Future.delayed(Duration.zero); // And here
var service = Get.find<CustomerServiceController>();
if (customerService != null) {
service.nameTextController.text = customerService.title;
service.descriptionTextController.text =
customerService.description;
service.priceTextController.text = customerService.price;
service.endTextController.text =
customerService.endDate ?? '';
service.serviceCategory = customerService.category!;
service.serviceType = customerService.service!;
service.serviceProvider = customerService.provider!;
service.isSubscription = customerService.isSubscription!;
} else {
service.nameTextController.text = '';
service.descriptionTextController.text = '';
service.priceTextController.text = '';
service.endTextController.text = '';
}
},
builder: (controller) {
return Column();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment