Skip to content

Commit

Permalink
fix(ui): Voucher exception when switching during load
Browse files Browse the repository at this point in the history
Fixes: Unhandled Exception: setState() called after dispose

When switching tabs before instruments/vouchers result has been
returned. Check if the widget is still mounted.
  • Loading branch information
kbn committed Dec 16, 2022
1 parent ae0aec7 commit 9f85714
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pages/home_voucher_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ class _RequestLessonState extends State<RequestLesson> {
void initState() {
super.initState();
locator<AuthModel>().getInstruments().then((List<Instrument> instruments) {
if (!mounted) return;
setState(() {
_instruments = instruments;
});
});
locator<AuthModel>().getVouchers().then((List<Voucher> vouchers) {
if (!mounted) return;
setState(() {
_vouchers = vouchers.where((v) => v.active).toList();
if (voucher == null && _vouchers?.isNotEmpty == true) {
Expand Down

0 comments on commit 9f85714

Please sign in to comment.