Skip to content
This repository was archived by the owner on Mar 7, 2023. It is now read-only.
This repository was archived by the owner on Mar 7, 2023. It is now read-only.

how to update UI in callback? #7

@lucasjinreal

Description

@lucasjinreal

I using a callback, when livestream gives me an emit message, can I need call setState to update UI,

but there was any error everytime I try to update UI:

E/flutter (19781): 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 (19781): 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 (19781): 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 (19781): #0      State.setState.<anonymous closure> (package:flutter/src/widgets/framework.dart:1112:9)
E/flutter (19781): #1      State.setState (package:flutter/src/widgets/framework.dart:1147:6)
E/flutter (19781): #2      _ChatPageState._solveReceivedMessage (package:tunnel/tab_page/tab1_children/chat_page3.dart:396:9)
E/flutter (19781): #3      _ChatPageState.initState.<anonymous closure> (package:tunnel/tab_page/tab1_children/chat_page3.dart:216:7)
E/flutter (19781): #4      _DataStore.setValue.<anonymous closure> (package:livestream/livestream.dart:54:15)

what should we properly update UI in callback?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions