diff --git a/lib/widgets/purchase_widget.dart b/lib/widgets/purchase_widget.dart index 6d3d05c4..e1c8d342 100644 --- a/lib/widgets/purchase_widget.dart +++ b/lib/widgets/purchase_widget.dart @@ -107,6 +107,12 @@ class _PurchaseWidgetState extends State { 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 { 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;