PurchaseWidget: Make sure it is still mounted before calling callback

Fixes APP-B1
This commit is contained in:
Vishesh Handa
2020-09-05 12:50:31 +02:00
parent 3bc459c73a
commit 16fae264de

View File

@ -107,6 +107,12 @@ class _PurchaseWidgetState extends State<PurchaseWidget> {
if (response.error != null) {
Log.e("IAP queryProductDetails: ${response.error}");
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
var products = response.productDetails;
products.sort((a, b) {
var pa = _fromProductDetail(a);
@ -122,11 +128,6 @@ class _PurchaseWidgetState extends State<PurchaseWidget> {
widget.minPurchaseOptionCallback(products.first.price);
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_products = products;
_selectedProduct = _products.isNotEmpty ? _products.first : null;