canonical / workshops

Workshops
GNU General Public License v3.0
51 stars 11 forks source link

OsLogo: guard against accessing the context when no longer mounted #261

Closed jpnurmi closed 1 year ago

jpnurmi commented 1 year ago

The SVG loading operations are asynchronous. We must not try to access DefaultAssetBundle.of(context) or Theme.of(context) when quickly scrolling long instance lists back and forth so that tiles get removed from the widget tree during SVG lookups or loading.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: This widget has been unmounted, so the State no longer has a context (and should be considered defunct).
Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active.
#0      State.context.<anonymous closure>
package:flutter/…/widgets/framework.dart:935
#1      State.context
package:flutter/…/widgets/framework.dart:941
#2      _OsLogoState._tryLoadSvg
package:os_logo/src/os_logo.dart:44
#3      _OsLogoState._loadSvg
package:os_logo/src/os_logo.dart:55
<asynchronous suspension>
#4      _OsLogoState._updateSvg
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: This widget has been unmounted, so the State no longer has a context (and should be considered defunct).
Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active.
#0      State.context.<anonymous closure>
package:flutter/…/widgets/framework.dart:935
#1      State.context
package:flutter/…/widgets/framework.dart:941
#2      _OsLogoState._loadSvg
package:os_logo/src/os_logo.dart:55
#3      _OsLogoState._updateSvg
package:os_logo/src/os_logo.dart:38
#4      _OsLogoState.initState.<anonymous closure>
package:os_logo/src/os_logo.dart:20
#5      SchedulerBinding._invokeFrameCallback
package:flutter/…/scheduler/binding.dart:1175
#6      SchedulerBinding.handleDrawFrame
package:flutter/…/scheduler/binding.dart:1113
#7      SchedulerBinding._handleDrawFrame
package:flutter/…/scheduler/binding.dart:1015
#8      _invoke (dart:ui/hooks.dart:148:13)
#9      PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:318:5)
#10     _drawFrame (dart:ui/hooks.dart:115:31)