I have 2 screens: ShowProductDetail and EditProductDetail.
The Product model
class Product {
String? id;
String? name;
String? description;
double? price;
double? discount;
int? originalStockCount;
int? currentStockCount;
}
And the controller
class ProductController extends GetxController {
var currentProduct = Product().obs
// aditional methods to update, delete etc
}
First I see the product detail on ShowProductDetail, then click the edit button to display EditProductDetail. Do some editings, and the go back to ShowProductDetail
Thanks to Obx, all widgets displaying the product detail with automatically updated accordingly, e.g.
Obx(() => Text(controller.currentProduct.value.description!,
style: TextStyle(fontSize: 15, color: Colors.purple))
But what if I want to access the recently updated values not on widget?
e.g
if (product.currentStockCount <= 10){
// show alert "Stock is reaching 0"
}
Assume product.currentStockCount
on EditProductDetail is updated from 30 to 8.
When I go back to ShowProductDetail, that part will not be executed, because product.currentStockCount
still refers to its old value, which is 30.
How to fix this?