mirror of
https://github.com/WuKongIM/WuKongIMFlutterSDK
synced 2025-06-01 16:42:48 +00:00
add custom message example
This commit is contained in:
parent
c1753a5c84
commit
708149d1a7
@ -7,6 +7,7 @@ import 'package:wukongimfluttersdk/proto/proto.dart';
|
|||||||
import 'package:wukongimfluttersdk/type/const.dart';
|
import 'package:wukongimfluttersdk/type/const.dart';
|
||||||
import 'package:wukongimfluttersdk/wkim.dart';
|
import 'package:wukongimfluttersdk/wkim.dart';
|
||||||
|
|
||||||
|
import 'custom_message.dart';
|
||||||
import 'msg.dart';
|
import 'msg.dart';
|
||||||
|
|
||||||
class ChatPage extends StatelessWidget {
|
class ChatPage extends StatelessWidget {
|
||||||
@ -365,9 +366,12 @@ class ChatListDataState extends State<ChatList> {
|
|||||||
_textEditingController.text = '';
|
_textEditingController.text = '';
|
||||||
Setting setting = Setting();
|
Setting setting = Setting();
|
||||||
setting.receipt = 1; //开启回执
|
setting.receipt = 1; //开启回执
|
||||||
WKTextContent text = WKTextContent(content);
|
// WKTextContent text = WKTextContent(content);
|
||||||
|
CustomMsg customMsg = CustomMsg(content);
|
||||||
WKIM.shared.messageManager.sendMessageWithSetting(
|
WKIM.shared.messageManager.sendMessageWithSetting(
|
||||||
text, WKChannel(channelID, channelType), setting);
|
customMsg,
|
||||||
|
WKChannel(channelID, channelType),
|
||||||
|
setting);
|
||||||
// WKImageContent imageContent = WKImageContent(100, 200);
|
// WKImageContent imageContent = WKImageContent(100, 200);
|
||||||
// imageContent.localPath = 'addskds';
|
// imageContent.localPath = 'addskds';
|
||||||
// WKIM.shared.messageManager.sendMessage(
|
// WKIM.shared.messageManager.sendMessage(
|
||||||
|
23
example/lib/custom_message.dart
Normal file
23
example/lib/custom_message.dart
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import 'package:wukongimfluttersdk/model/wk_message_content.dart';
|
||||||
|
|
||||||
|
class CustomMsg extends WKMessageContent {
|
||||||
|
var name = "";
|
||||||
|
CustomMsg(this.name) {
|
||||||
|
contentType = 12;
|
||||||
|
}
|
||||||
|
@override
|
||||||
|
Map<String, dynamic> encodeJson() {
|
||||||
|
return {"name": name};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
WKMessageContent decodeJson(Map<String, dynamic> json) {
|
||||||
|
name = json["name"];
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String displayText() {
|
||||||
|
return "我是自定义消息:$name";
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ import 'package:wukongimfluttersdk/model/wk_voice_content.dart';
|
|||||||
import 'package:wukongimfluttersdk/type/const.dart';
|
import 'package:wukongimfluttersdk/type/const.dart';
|
||||||
import 'package:wukongimfluttersdk/wkim.dart';
|
import 'package:wukongimfluttersdk/wkim.dart';
|
||||||
|
|
||||||
|
import 'custom_message.dart';
|
||||||
import 'http.dart';
|
import 'http.dart';
|
||||||
|
|
||||||
class IMUtils {
|
class IMUtils {
|
||||||
@ -21,6 +22,9 @@ class IMUtils {
|
|||||||
WKIM.shared.connectionManager.connect();
|
WKIM.shared.connectionManager.connect();
|
||||||
initListener();
|
initListener();
|
||||||
}
|
}
|
||||||
|
// 注册自定义消息
|
||||||
|
WKIM.shared.messageManager
|
||||||
|
.registerMsgContent(12, (data) => CustomMsg("").decodeJson(data));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ version: 1.2.4
|
|||||||
homepage: https://github.com/WuKongIM/WuKongIMFlutterSDK
|
homepage: https://github.com/WuKongIM/WuKongIMFlutterSDK
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.0.6 <4.0.0'
|
sdk: '>=2.0.0 <4.0.0'
|
||||||
|
|
||||||
# Dependencies specify other packages that your package needs in order to work.
|
# Dependencies specify other packages that your package needs in order to work.
|
||||||
# To automatically upgrade your package dependencies to the latest versions
|
# To automatically upgrade your package dependencies to the latest versions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user