小编Gre*_*kes的帖子

Tab 更改后 Flutter Socket IO 无法获取数据

因此,当我第一次打开该选项卡时,会显示来自 Socket.IO 的数据。但是当我更改选项卡并返回时,我无法从 Socket.IO 获取数据。

这是我的代码:

Map <String,dynamic> list;

IO.Socket socket = IO.io('http://localhost:3000', <String, dynamic>{
    'transports': ['websocket'] 
});

@override
initState(){
socket.on('connect',(_){
      socket.on('stockQuote',(jsonData){
        setState(() {
          list = jsonData;
          isLoading = false;
        });
      });
    });
super.initState();
}

dispose(){
    super.dispose();
  }
Run Code Online (Sandbox Code Playgroud)

我收到这些错误:

Unhandled Exception: setState() called after dispose(): _StocksState#0faab(lifecycle state: defunct, not mounted)
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 …
Run Code Online (Sandbox Code Playgroud)

sockets super socket.io flutter

1
推荐指数
1
解决办法
1518
查看次数

标签 统计

flutter ×1

socket.io ×1

sockets ×1

super ×1