今天被flutter不更新组件状态搞得差点找不到北。
@override
void initState() {
super.initState();
textController = TextEditingController(text: '');
//进行登录校验 准备websocket连接
_checkWs(context);
layoutLists = makeLayoutLists();
}
看似没啥问题,程序并没有任何异常,但是_checkWs里有联网请求+
setState,一开始我并没有察觉。
后来才发现后续的setState刷新组件开始出问题了。
//解决方法是移动以下代码不要放在 initState
_checkWs(context);
layoutLists = makeLayoutLists();
//也就是说问题与initState有关