herodotdigital / SnakeBottomNavigationBar

Apache License 2.0
207 stars 51 forks source link

setState() called after dispose() #20

Open mohammadreza490 opened 3 years ago

mohammadreza490 commented 3 years ago

I'm using flutter_snake_navigationbar: ^0.4.2 and when I navigate to a new screen, I get this error:

E/flutter ( 4369): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: setState() called after dispose(): _SnakeViewState#3e337(lifecycle state: defunct, not mounted)
E/flutter ( 4369): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
E/flutter ( 4369): The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
E/flutter ( 4369): This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
E/flutter ( 4369): #0      State.setState.<anonymous closure> 
package:flutter/…/widgets/framework.dart:1208
E/flutter ( 4369): #1      State.setState 
package:flutter/…/widgets/framework.dart:1243
E/flutter ( 4369): #2      _SnakeViewState._goLeft.<anonymous closure> 
package:flutter_snake_navigationbar/src/snake_view.dart:151
E/flutter ( 4369): #3      new Future.delayed.<anonymous closure>  (dart:async/future.dart:326:39)
E/flutter ( 4369): #4      _rootRun  (dart:async/zone.dart:1182:47)
E/flutter ( 4369): #5      _CustomZone.run  (dart:async/zone.dart:1093:19)
E/flutter ( 4369): #6      _CustomZone.runGuarded  (dart:async/zone.dart:997:7)
E/flutter ( 4369): #7      _CustomZone.bindCallbackGuarded.<anonymous closure>  (dart:async/zone.dart:1037:23)
E/flutter ( 4369): #8      _rootRun  (dart:async/zone.dart:1190:13)
E/flutter ( 4369): #9      _CustomZone.run  (dart:async/zone.dart:1093:19)
E/flutter ( 4369): #10     _CustomZone.bindCallback.<anonymous closure>  (dart:async/zone.dart:1021:23)
E/flutter ( 4369): #11     Timer._createTimer.<anonymous closure>  (dart:async-patch/timer_patch.dart:18:15)
E/flutter ( 4369): #12     _Timer._runTimers  (dart:isolate-patch/timer_impl.dart:397:19)
E/flutter ( 4369): #13     _Timer._handleMessage  (dart:isolate-patch/timer_impl.dart:428:5)
E/flutter ( 4369): #14     _RawReceivePortImpl._handleMessage  (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter ( 4369):

When I use a BottomNavigationBar() widget, the error is gone.

This is my Flutter Doctor result:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.5, on macOS 11.0.1 20B29 darwin-x64, locale en-GB)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 12.2)
[!] Android Studio (version 4.1)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] IntelliJ IDEA Community Edition (version 2020.2.3)

[✓] Connected device (1 available)            
GoltVik commented 3 years ago

Hello @mohammadreza490 ! Can you provide code to reproduce this error ? This is will be very helpful to understand the problem.

mohammadreza490 commented 3 years ago

I have different screens and I use this navigation bar to navigate to these screens. There is nothing special about the code.