报错

来源:14-1 本章介绍

weixin_慕沐0518080

2023-10-19

I/flutter (26489): db ver:0
E/flutter (26489): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: setState() called after dispose(): _ConversationListPageState#0ed9f(lifecycle state: defunct, not mounted)
E/flutter (26489): 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 (26489): 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 (26489): 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 (26489): #0      State.setState.<anonymous closure> (package:flutter/src/widgets/framework.dart:1102:9)
E/flutter (26489): #1      State.setState (package:flutter/src/widgets/framework.dart:1137:6)
E/flutter (26489): #2      _ConversationListPageState._loadStickData (package:chatgpt_flutter/pages/conversation_list_page.dart:89:5)

这个报错是因为啥呀,代码写的和课中的代码是一样的

写回答

1回答

CrazyCodeBoy

2023-10-19

这个可以忽略。
原因是因为页面销毁后还有调用setState所以抛出了这个log,后面课程中有讲到如何防止出现这个log。
0
0

ChatGPT + Flutter快速开发多端聊天机器人App

ChatGPT + Flutter快速开发多端聊天机器人App

343 学习 · 90 问题

查看课程