rickypid/flutter_scroll_shadow

setState() called after dispose(): _ScrollShadowState#670d0(lifecycle state: defunct, not mounted)

Closed this issue · 4 comments

Issue Description:
I am encountering an error while working with a FutureBuilder in my Flutter application. The error message I'm receiving is:

`setState() called after dispose(): _ScrollShadowState#670d0(lifecycle state: defunct, not mounted)

When the exception was thrown, this was the stack:
#0 State.setState. (package:flutter/src/widgets/framework.dart:1102:9)
#1 State.setState (package:flutter/src/widgets/framework.dart:1137:6)
#2 _ScrollShadowState._update. (package:flutter_scroll_shadow/src/scroll_shadow.dart:105:9)
#3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1297:15)
#4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1236:9)
#5 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1085:5)
#6 _invoke (dart:ui/hooks.dart:170:13)
#7 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:401:5)
`

Steps to Reproduce:

  1. Set up a FutureBuilder in a Flutter widget.
  2. Fetch data asynchronously using the FutureBuilder.
  3. Perform a setState operation within the FutureBuilder's builder callback.
  4. Navigate away from the widget or trigger a dispose event before the FutureBuilder completes.

Expected Behavior:
I expected the FutureBuilder to handle state updates appropriately and avoid the "setState() called after dispose()" error even when navigating away from the widget.

Actual Behavior:
The error occurs when the setState operation is executed within the FutureBuilder after navigating away from the widget or during a dispose event.

Additional Information:

  • Flutter version: [insert your Flutter version]
  • Dart version: [insert your Dart version]
  • Reproducible code snippet: [provide a code snippet where the issue can be replicated]
  • Any relevant logs or screenshots: [include any relevant logs or screenshots that might help in understanding the issue better]

I'm not sure if I'm missing something or if this is a bug. Any insights or suggestions on how to resolve or work around this issue would be greatly appreciated. Thank you!

Hi @AravinthC-18,

With the new version v1.2.1 this bug has been fixed. Try it and give me feedback.

Special thanks to @RichiB20 for the contribution!

It doesn't solve the problem but gives you yet another bug. You're not allowed to use dependOnInheritedWidgetOfExactType in initState or didUpdateWidget.

Please, here you are #9

Fixed in v1.2.2