From 9f85714be22d23d5252490b6eb4a3cea1dee510e Mon Sep 17 00:00:00 2001 From: Kristian Berge Nessa Date: Fri, 16 Dec 2022 20:52:13 +0100 Subject: [PATCH] fix(ui): Voucher exception when switching during load Fixes: Unhandled Exception: setState() called after dispose When switching tabs before instruments/vouchers result has been returned. Check if the widget is still mounted. --- lib/pages/home_voucher_tab.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/pages/home_voucher_tab.dart b/lib/pages/home_voucher_tab.dart index 59fe980..fee7137 100644 --- a/lib/pages/home_voucher_tab.dart +++ b/lib/pages/home_voucher_tab.dart @@ -42,11 +42,13 @@ class _RequestLessonState extends State { void initState() { super.initState(); locator().getInstruments().then((List instruments) { + if (!mounted) return; setState(() { _instruments = instruments; }); }); locator().getVouchers().then((List vouchers) { + if (!mounted) return; setState(() { _vouchers = vouchers.where((v) => v.active).toList(); if (voucher == null && _vouchers?.isNotEmpty == true) {