This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Fix:avoid calling setState() when mounted is false.#2360
Closed
Notzuonotdied wants to merge 1 commit intoflutter:masterfrom
Closed
Fix:avoid calling setState() when mounted is false.#2360Notzuonotdied wants to merge 1 commit intoflutter:masterfrom
Notzuonotdied wants to merge 1 commit intoflutter:masterfrom
Conversation
It is an error to call [setState] unless [mounted] is true.
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It is an error to call [setState] unless [mounted] is true.
Description
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.
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().
#0 State.setState. (package:flutter/src/widgets/framework.dart:1105:9)
#1 State.setState (package:flutter/src/widgets/framework.dart:1140:6)
#2 SnakeState.initState. (package:.../qy_sensors/snake.dart:77:7) // setState()
#3 _rootRunUnary (dart:async/zone.dart:1132:38)
#4 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#5 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#6 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#7 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#8 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:132:11)
#9 _MapStream._handleData (dart:async/stream_pipe.dart:232:10)
#10 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:164:13)
#11 _rootRunUnary (dart:async/zone.dart:1132:38)
#12 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#13 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#14 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#15 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
#16 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
#17 _PendingEvents.schedule. (dart:async/stream_impl.dart:667:7)
#18 _rootRun (dart:async/zone.dart:1120:38)
#19 _CustomZone.run (dart:async/zone.dart:1021:19)
#20 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#21 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963:23)
#22 _rootRun (dart:async/zone.dart:1124:13)
#23 _CustomZone.run (dart:async/zone.dart:1021:19)
#24 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#25 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963:23)
#26 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#27 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)