diff --git a/lib/barcode.dart b/lib/barcode.dart index 10a40bad..3b87770d 100644 --- a/lib/barcode.dart +++ b/lib/barcode.dart @@ -626,9 +626,9 @@ class _QRViewState extends State { flash_status = status != null && status; // Reload - setState(() { - - }); + if (mounted) { + setState(() {}); + } } // In order to get hot reload to work we need to pause the camera if the platform diff --git a/lib/settings/app_settings.dart b/lib/settings/app_settings.dart index d788d646..be5fa64a 100644 --- a/lib/settings/app_settings.dart +++ b/lib/settings/app_settings.dart @@ -46,8 +46,9 @@ class _InvenTreeAppSettingsState extends State { reportErrors = await InvenTreeSettingsManager().getValue(INV_REPORT_ERRORS, true) as bool; strictHttps = await InvenTreeSettingsManager().getValue(INV_STRICT_HTTPS, false) as bool; - setState(() { - }); + if (mounted) { + setState(() {}); + } } @override diff --git a/lib/widget/home.dart b/lib/widget/home.dart index 3b31f235..84fef290 100644 --- a/lib/widget/home.dart +++ b/lib/widget/home.dart @@ -177,7 +177,9 @@ class _InvenTreeHomePageState extends State { // Attempt server connection InvenTreeAPI().connectToServer().then((result) { - setState(() {}); + if (mounted) { + setState(() {}); + } }); } } diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index 7e32c5bf..0eaad482 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -128,7 +128,9 @@ class _LocationDisplayState extends RefreshableState { } } - setState(() {}); + if (mounted) { + setState(() {}); + } } Future _newLocation(BuildContext context) async { diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index 15cc7011..ef63f483 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -91,9 +91,9 @@ class _PartDisplayState extends RefreshableState { Future onBuild(BuildContext context) async { refresh(context); - setState(() { - - }); + if (mounted) { + setState(() {}); + } } @override @@ -123,8 +123,9 @@ class _PartDisplayState extends RefreshableState { // Request part test templates part.getTestTemplates().then((value) { - setState(() { - }); + if (mounted) { + setState(() {}); + } }); // Request the number of attachments @@ -133,9 +134,11 @@ class _PartDisplayState extends RefreshableState { "part": part.pk.toString(), } ).then((int value) { - setState(() { - attachmentCount = value; - }); + if (mounted) { + setState(() { + attachmentCount = value; + }); + } }); // Request the number of BOM items @@ -144,9 +147,11 @@ class _PartDisplayState extends RefreshableState { "in_bom_for": part.pk.toString(), } ).then((int value) { - setState(() { - bomCount = value; - }); + if (mounted) { + setState(() { + bomCount = value; + }); + } }); // Request the number of variant items @@ -155,9 +160,11 @@ class _PartDisplayState extends RefreshableState { "variant_of": part.pk.toString(), } ).then((int value) { - setState(() { - variantCount = value; - }); + if (mounted) { + setState(() { + variantCount = value; + }); + } }); } diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index d03f3904..77804d7e 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -124,9 +124,12 @@ class _StockItemDisplayState extends RefreshableState { // Request test results (async) item.getTestResults().then((value) { - setState(() { - // Update - }); + + if (mounted) { + setState(() { + // Update + }); + } }); // Request the number of attachments @@ -135,9 +138,12 @@ class _StockItemDisplayState extends RefreshableState { "stock_item": item.pk.toString() } ).then((int value) { - setState(() { - attachmentCount = value; - }); + + if (mounted) { + setState(() { + attachmentCount = value; + }); + } }); // Request information on labels available for this stock item @@ -169,8 +175,9 @@ class _StockItemDisplayState extends RefreshableState { } } - setState(() { - }); + if (mounted) { + setState(() {}); + } } }); }