Reputation: 6938
The Obx can be used to observe widget when any related item change, but if the related item change before return widget (like the if statement), how should set this properly?
@override
Widget build(BuildContext context) {
Obx(
if (...) {
...
}
);
return ...
}
Upvotes: 1
Views: 1234
Reputation: 21
This works with me with multiple condition:
body: Obx(() {
if (controller.loadingState.value == LoadingState.loading) {
return const CircularProgressIndicator(
color: Colors.red,
);
} else if (controller.loadingState.value == LoadingState.loading) {
return Center();
} else {
return Center();
}
})
Upvotes: 2
Reputation: 337
You cant make if statement observable because if statement cant returns the value/ widget. so if you want to use obx use ternary operator because it returns the value and works same as if condition.
Upvotes: 0