mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-31 13:25:40 +00:00 
			
		
		
		
	Check if widget is mounted before calling setstate() (#193)
This commit is contained in:
		| @@ -177,7 +177,9 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> { | ||||
|  | ||||
|         // Attempt server connection | ||||
|         InvenTreeAPI().connectToServer().then((result) { | ||||
|           setState(() {}); | ||||
|           if (mounted) { | ||||
|             setState(() {}); | ||||
|           } | ||||
|         }); | ||||
|       } | ||||
|     } | ||||
|   | ||||
| @@ -128,7 +128,9 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> { | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     setState(() {}); | ||||
|     if (mounted) { | ||||
|       setState(() {}); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   Future<void> _newLocation(BuildContext context) async { | ||||
|   | ||||
| @@ -91,9 +91,9 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> { | ||||
|   Future<void> onBuild(BuildContext context) async { | ||||
|     refresh(context); | ||||
|  | ||||
|     setState(() { | ||||
|  | ||||
|     }); | ||||
|     if (mounted) { | ||||
|       setState(() {}); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   @override | ||||
| @@ -123,8 +123,9 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> { | ||||
|  | ||||
|     // 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<PartDetailWidget> { | ||||
|         "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<PartDetailWidget> { | ||||
|         "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<PartDetailWidget> { | ||||
|         "variant_of": part.pk.toString(), | ||||
|       } | ||||
|     ).then((int value) { | ||||
|       setState(() { | ||||
|         variantCount = value; | ||||
|       }); | ||||
|       if (mounted) { | ||||
|         setState(() { | ||||
|           variantCount = value; | ||||
|         }); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -124,9 +124,12 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> { | ||||
|  | ||||
|     // 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<StockDetailWidget> { | ||||
|         "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<StockDetailWidget> { | ||||
|           } | ||||
|         } | ||||
|  | ||||
|         setState(() { | ||||
|         }); | ||||
|         if (mounted) { | ||||
|           setState(() {}); | ||||
|         } | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user