I recive data from datareciver listener and added to my object list but I cant upload listview from another class. So is there a listener for listview to update when data recive.
I put all my class and code
ContentModel.dart -which is my Model
class ContentModel{
String dialogID;
DialogModel(this.dialogID);
}
Global.dart --Global class to store list
class Globals {
static List<ContentModel> dialogList =new List<ContentModel>();
}
main.dart --main view to display my list when its recive
List<ContentModel> _contentModel = Globals.dialogList;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child:ListView.builder(
padding: EdgeInsets.symmetric(horizontal: 12.0),
itemCount:_contentModel.length,
reverse: false,
controller: _scrollController,
itemBuilder: (BuildContext context, index) =>
buildChat(_contentModel[index]))
));
}
DataReciver.dart --Data reciver can recive any time and save it on global list
class QuickBloxListenerManager{
onMassageRecive(Function fun) async
{
try {
await QB.chat.subscribeChatEvent(QBChatEvents.RECEIVED_NEW_MESSAGE,
(data) {
print( "New Message Arrive...");
Map<String, Object> map = new Map<String, dynamic>.from(data);
Map<String, Object> payload =
new Map<String, dynamic>.from(map["payload"]);
ContentModel newMsg = new ContentModel();
newMsg.dialogID=payload['id'];
Globals.messageList.messages.add(newMsg);
}, onErrorMethod: (error) {
});
} on PlatformException catch (e) {
}
}
}
question from:
https://stackoverflow.com/questions/65902004/flutter-how-to-refresh-listview-on-data-recive-from-another-class 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…