暂停聊天收集模式

时间:2019-07-14 12:32:12

标签: collections flutter dart chat

我遇到了问题收集的实现。我需要与添加新消息添加到集合底部的聊天集合聊天,向上滚动时,我需要对旧消息进行打包,但是我不知道如何在dart / flutter中实现它。

我有过收集收藏的经验,但只有一种方法one way

//  send new message
    sendMessage(String body) {
        client.broadcastMessage(
          Message()
            ..id = user.id
            ..content = body
            ..type = "0"
            ..timestamp = DateTime.now().toIso8601String(),
        );
      }
// when use sendMessage add new message into this stream
// message stream from server
      Observable<Message> recieveMessage() {
        Connect connect = Connect()
          ..user = user
          ..active = true;

        return Observable(client.createStream(connect));
      }


StreamBuilder(
              stream: ErrorHandler().executeWithHandle(() {
                return MessageRepository.getInstance().recieveMessage();
              }),
              builder: (context, AsyncSnapshot<Message> snapshot) {
                if (snapshot.hasError) {
                  print("handled error ${snapshot.error.toString()}");
                }
                if (!snapshot.hasData) {
                  return Center(
                      child: CircularProgressIndicator(
                          valueColor:
                              AlwaysStoppedAnimation<Color>(themeColor)));
                } else {
                   // messages is Set<Message>
                  messages.add(snapshot.data);
                  return ListView(
                    children: messages
                        .map((msg) => ListTile(
                              leading: Text(msg.id.substring(0, 4)),
                              title: Text(msg.content),
                              subtitle: Text(msg.timestamp),
                            ))
                        .toList(),
                  );
                }
              },
            ),

使用此代码,我看到所有消息在运行活动时都已发送,我不知道如何编辑此代码(或服务器响应),以便将功能扩展到旧消息上并向集合底部添加新消息。 信使和所有聊天应用中的收藏都一样

请给我这个用​​例的一些模式。

谢谢

0 个答案:

没有答案