flutter 踩坑日記....
我在使用TabBar配合TabBarView使用的時(shí)候遇到了這個(gè)問題setState()在dispose()之后調(diào)用
FlutterError (setState() called after dispose(): _TimeLineState#fdb61(lifecycle state: defunct, not mounted, ticker inactive) 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. 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().)
打印臺(tái)描述的很清楚?"首選解決方案是取消計(jì)時(shí)器或停止偵聽dispose()回調(diào)中的動(dòng)畫。 另一種解決方案是在調(diào)用setState()之前檢查此對象的“已掛載”屬性相满,以確保該對象仍在樹中憋沿。"。
在dispose的時(shí)候感覺并沒有解決到問題,嗯,繼續(xù)面對google開發(fā),終于在stackoverflow找到同一個(gè)問題的帖子,在dispose()之后調(diào)用的setState(),于是..........
只需要在setState()前添加一個(gè)!mounted的判斷當(dāng)前頁面是否存在于構(gòu)件樹中,存在賦值,不存在結(jié)束操作。