mirror of
https://github.com/WuKongIM/WuKongIMFlutterSDK
synced 2025-05-24 02:42:20 +00:00
update example show channel info
This commit is contained in:
parent
687abd8bd8
commit
8a555c4833
@ -2,6 +2,8 @@ import 'package:wukongimfluttersdk/entity/conversation.dart';
|
||||
|
||||
class UIConversation {
|
||||
String lastContent = '';
|
||||
String channelAvatar = '';
|
||||
String channelName = '';
|
||||
WKUIConversationMsg msg;
|
||||
UIConversation(this.msg);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:example/const.dart';
|
||||
import 'package:example/msg.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wukongimfluttersdk/entity/conversation.dart';
|
||||
import 'package:wukongimfluttersdk/type/const.dart';
|
||||
@ -42,6 +43,7 @@ class ListViewShowDataState extends State<ListViewShowData> {
|
||||
|
||||
var _connectionStatusStr = '';
|
||||
_initListener() {
|
||||
// 监听连接状态事件
|
||||
WKIM.shared.connectionManager.addOnConnectionStatus('home',
|
||||
(status, reason) {
|
||||
if (status == WKConnectStatus.connecting) {
|
||||
@ -55,6 +57,7 @@ class ListViewShowDataState extends State<ListViewShowData> {
|
||||
}
|
||||
setState(() {});
|
||||
});
|
||||
// 监听更新消息事件
|
||||
WKIM.shared.conversationManager.addOnRefreshMsgListener('chat_conversation',
|
||||
(msg, isEnd) async {
|
||||
bool isAdd = true;
|
||||
@ -74,6 +77,17 @@ class ListViewShowDataState extends State<ListViewShowData> {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
// 监听刷新channel资料事件
|
||||
WKIM.shared.channelManager.addOnRefreshListener("cover_chat", (channel) {
|
||||
for (var i = 0; i < msgList.length; i++) {
|
||||
if (msgList[i].msg.channelID == channel.channelID &&
|
||||
msgList[i].msg.channelType == channel.channelType) {
|
||||
msgList[i].msg.setWkChannel(channel);
|
||||
setState(() {});
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _getDataList() {
|
||||
@ -101,6 +115,35 @@ class ListViewShowDataState extends State<ListViewShowData> {
|
||||
return uiConversation.lastContent;
|
||||
}
|
||||
|
||||
String getChannelAvatarURL(UIConversation uiConversation) {
|
||||
if (uiConversation.channelAvatar == '') {
|
||||
uiConversation.msg.getWkChannel().then((channel) {
|
||||
if (channel != null) {
|
||||
uiConversation.channelAvatar = channel.avatar;
|
||||
}
|
||||
});
|
||||
}
|
||||
return uiConversation.channelAvatar;
|
||||
}
|
||||
|
||||
String getChannelName(UIConversation uiConversation) {
|
||||
if (uiConversation.channelName == '') {
|
||||
uiConversation.msg.getWkChannel().then((channel) {
|
||||
if (channel != null) {
|
||||
if (channel.channelRemark == '') {
|
||||
uiConversation.channelName = channel.channelName;
|
||||
} else {
|
||||
uiConversation.channelName = channel.channelRemark;
|
||||
}
|
||||
} else {
|
||||
WKIM.shared.channelManager.fetchChannelInfo(
|
||||
uiConversation.msg.channelID, uiConversation.msg.channelType);
|
||||
}
|
||||
});
|
||||
}
|
||||
return uiConversation.channelName;
|
||||
}
|
||||
|
||||
Widget _buildRow(UIConversation uiMsg) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(10),
|
||||
@ -115,12 +158,11 @@ class ListViewShowDataState extends State<ListViewShowData> {
|
||||
alignment: Alignment.center,
|
||||
height: 50,
|
||||
margin: const EdgeInsets.fromLTRB(0, 0, 10, 0),
|
||||
child: Text(
|
||||
CommonUtils.getAvatar(uiMsg.msg.channelID),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold),
|
||||
child: Image.network(
|
||||
getChannelAvatarURL(uiMsg),
|
||||
height: 200,
|
||||
width: 200,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
@ -131,7 +173,7 @@ class ListViewShowDataState extends State<ListViewShowData> {
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
uiMsg.msg.channelID,
|
||||
getChannelName(uiMsg),
|
||||
style:
|
||||
const TextStyle(color: Colors.black, fontSize: 18),
|
||||
maxLines: 1,
|
||||
|
@ -1,5 +1,8 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:example/const.dart';
|
||||
import 'package:wukongimfluttersdk/common/options.dart';
|
||||
import 'package:wukongimfluttersdk/entity/channel.dart';
|
||||
import 'package:wukongimfluttersdk/model/wk_image_content.dart';
|
||||
import 'package:wukongimfluttersdk/model/wk_video_content.dart';
|
||||
import 'package:wukongimfluttersdk/model/wk_voice_content.dart';
|
||||
@ -23,6 +26,15 @@ class IMUtils {
|
||||
}
|
||||
|
||||
static initListener() {
|
||||
var imgs = [
|
||||
"https://lmg.jj20.com/up/allimg/tx29/06052048151752929.png",
|
||||
"https://pic.imeitou.com/uploads/allimg/2021061715/aqg1wx3nsds.jpg",
|
||||
"https://lmg.jj20.com/up/allimg/tx30/10121138219844229.jpg",
|
||||
"https://lmg.jj20.com/up/allimg/tx30/10121138219844229.jpg",
|
||||
"https://lmg.jj20.com/up/allimg/tx28/430423183653303.jpg",
|
||||
"https://lmg.jj20.com/up/allimg/tx23/520420024834916.jpg"
|
||||
];
|
||||
|
||||
WKIM.shared.messageManager.addOnSyncChannelMsgListener((channelID,
|
||||
channelType, startMessageSeq, endMessageSeq, limit, pullMode, back) {
|
||||
print('回掉接口');
|
||||
@ -30,7 +42,27 @@ class IMUtils {
|
||||
HttpUtils.syncChannelMsg(channelID, channelType, startMessageSeq,
|
||||
endMessageSeq, limit, pullMode, (p0) => back(p0));
|
||||
});
|
||||
|
||||
// 获取channel资料
|
||||
WKIM.shared.channelManager
|
||||
.addOnGetChannelListener((channelId, channelType, back) {
|
||||
if (channelType == WKChannelType.personal) {
|
||||
// 获取个人资料
|
||||
// 这里直接返回了。实际情况可通过API请求后返回
|
||||
var channel = WKChannel(channelId, channelType);
|
||||
channel.channelName = "单聊${channel.channelID.hashCode}";
|
||||
var index = channel.channelID.hashCode % imgs.length;
|
||||
channel.avatar = imgs[index];
|
||||
back(channel);
|
||||
} else if (channelType == WKChannelType.group) {
|
||||
// 获取群资料
|
||||
var channel = WKChannel(channelId, channelType);
|
||||
channel.channelName = "群聊${channel.channelID.hashCode}";
|
||||
var index = channel.channelID.hashCode % imgs.length;
|
||||
channel.avatar = imgs[index];
|
||||
back(channel);
|
||||
back(channel);
|
||||
}
|
||||
});
|
||||
WKIM.shared.conversationManager
|
||||
.addOnSyncConversationListener((lastSsgSeqs, msgCount, version, back) {
|
||||
HttpUtils.syncConversation(lastSsgSeqs, msgCount, version, back);
|
||||
|
42
pubspec.lock
42
pubspec.lock
@ -61,10 +61,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: collection
|
||||
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
|
||||
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.17.1"
|
||||
version: "1.18.0"
|
||||
connectivity:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -244,26 +244,26 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: matcher
|
||||
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
|
||||
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.12.15"
|
||||
version: "0.12.16"
|
||||
material_color_utilities:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: material_color_utilities
|
||||
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
|
||||
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.2.0"
|
||||
version: "0.5.0"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
|
||||
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
version: "1.10.0"
|
||||
path:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -385,10 +385,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_span
|
||||
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
|
||||
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
version: "1.10.0"
|
||||
sqflite:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -409,18 +409,18 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stack_trace
|
||||
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
|
||||
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.11.0"
|
||||
version: "1.11.1"
|
||||
stream_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stream_channel
|
||||
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
|
||||
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
version: "2.1.2"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -449,10 +449,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
|
||||
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.5.1"
|
||||
version: "0.6.1"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -477,6 +477,14 @@ packages:
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web
|
||||
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.3.0"
|
||||
web_socket_channel:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -510,5 +518,5 @@ packages:
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
sdks:
|
||||
dart: ">=3.0.6 <4.0.0"
|
||||
dart: ">=3.2.0-194.0.dev <4.0.0"
|
||||
flutter: ">=3.3.0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user