Add this line of code inside your stream listen function, under initState.
if (!mounted) { return; }
@override void initState() { Provider.of(context, listen: false) .websocketChatConnectToRoom('room1'); channel = Provider.of (context, listen: false).channel!; channel!.stream.listen((str) { if (!mounted) { return; } if (str != '') { dynamic decodedData = json.decode(str); chatData.add(ChatItem( userId: decodedData['Account'].toString(), dateTime: DateTime.parse(decodedData['datetime']), message: decodedData['message'], image: '', fromName: decodedData['from_name'], )); setState(() {}); } }); super.initState(); }
Add new comment