增加描述 - 宽展代码可读性

This commit is contained in:
Jin857 2025-01-11 14:39:57 +08:00
parent c88aa27015
commit 65d34fef4d
9 changed files with 171 additions and 125 deletions

View File

@ -11,6 +11,16 @@
import 'package:wukongimfluttersdk/wkim.dart';
```
**安装方式**
需要手动下载该项目到本地,注意:与你的开发项目在同一目录下
1. 打开pubspec
项目目录下找到 pubspec.yaml
2. 在 dependencies 中添加
```yaml
wukongimfluttersdk:
path: ../wkim/
```
**初始化sdk**
```dart
WKIM.shared.setup(Options.newDefault('uid', 'token'));
@ -27,6 +37,7 @@ WKIM.shared.options.getAddr = (Function(String address) complete) async {
```dart
WKIM.shared.connectionManager.connect();
```
**断开**
```dart
// isLogout true退出并不再重连 false退出保持重连
@ -57,18 +68,21 @@ WKIM.shared.connectionManager.addOnConnectionStatus('home',
}
});
```
**消息入库**
```dart
WKIM.shared.messageManager.addOnMsgInsertedListener((wkMsg) {
// todo 展示在UI上
});
```
**收到新消息**
```dart
WKIM.shared.messageManager.addOnNewMsgListener('chat', (msgs) {
// todo 展示在UI上
});
```
**刷新某条消息**
```dart
WKIM.shared.messageManager.addOnRefreshMsgListener('chat', (wkMsg) {
@ -82,6 +96,7 @@ WKIM.shared.cmdManager.addOnCmdListener('chat', (cmdMsg) {
// todo 按需处理cmd消息
});
```
- 包含`key`的事件监听均有移除监听的方法,为了避免重复收到事件回掉,在退出或销毁页面时通过传入的`key`移除事件
**发送消息时间**
@ -100,8 +115,8 @@ ntp7.aliyun.com
**Socket链接逻辑**
将socket链接分成两部分: (链接成功之前,链接成功之后)这里是根据是否有返回消息/结合onDone来判断
1.链接成功之前:(链接中)
当前没有任何处理,链接不成功的话不回重复链接。
需求是 链接不成功 时 每隔1.5秒重新链接
链接不成功 时 每隔5秒重新链接。即没有返回消息并且onDone触发时会触发 5秒 后断线重连
当 WKIM.shared.connectionManager.disconnect 时会清理掉计时器
2.链接成功之后
接首到消息返回,开启心跳检测/网络异常监听

View File

@ -1,49 +1,70 @@
import '../type/const.dart';
///
class WKChannel {
String channelID = "";
int channelType = WKChannelType.personal;
String channelName = "";
//()
/// ()
String channelRemark = "";
int showNick = 0;
//
///
int top = 0;
//
///
int save = 0;
//
///
int mute = 0;
//
///
int forbidden = 0;
//
///
int invite = 0;
//[12]
/// [12]
int status = 1;
// 0. 1.
/// 0. 1.
int follow = 0;
//
///
int isDeleted = 0;
//
///
String createdAt = "";
//
///
String updatedAt = "";
//
///
String avatar = "";
//
///
int version = 0;
//
///
dynamic localExtra;
//线
/// 线
int online = 0;
//线
/// 线
int lastOffline = 0;
// 线
/// 线
int deviceFlag = 0;
//
///
int receipt = 0;
//
///
int robot = 0;
//[service:]
/// [service:]
String category = "";
String username = "";
String avatarCacheKey = "";
@ -53,8 +74,10 @@ class WKChannel {
WKChannel(this.channelID, this.channelType);
}
///
class WKChannelSearchResult {
WKChannel? channel;
//
///
String containMemberName = '';
}

View File

@ -1,36 +1,53 @@
///
class WKChannelMember {
String channelID = "";
//
///
int channelType = 0;
//id
/// id
String memberUID = "";
//
///
String memberName = "";
//
///
String memberRemark = "";
//
///
String memberAvatar = "";
//
///
int role = 0;
//12
/// 12
int status = 0;
//
///
int isDeleted = 0;
//
///
String createdAt = "";
//
///
String updatedAt = "";
//
///
int version = 0;
// 01
/// 01
int robot = 0;
//
///
dynamic extraMap;
//
///
String remark = "";
// uid
/// uid
String memberInviteUID = "";
//
///
int forbiddenExpirationTime = 0;
String memberAvatarCacheKey = "";
}

View File

@ -1,8 +1,10 @@
///
class WkSyncCMD {
String cmd = '';
dynamic param;
}
///
class WKCMD {
String cmd = '';
dynamic param;

View File

@ -6,30 +6,40 @@ import 'cmd.dart';
import 'msg.dart';
import 'reminder.dart';
///
class WKConversationMsg {
//id
/// id
String channelID = '';
//
///
int channelType = WKChannelType.personal;
//ID
/// ID
String lastClientMsgNO = '';
//
///
int isDeleted = 0;
//
///
int version = 0;
//
///
int lastMsgTimestamp = 0;
//
///
int unreadCount = 0;
//
///
int lastMsgSeq = 0;
//
///
dynamic localExtraMap;
WKConversationMsgExtra? msgExtra;
String parentChannelID = '';
int parentChannelType = 0;
}
///
class WKConversationMsgExtra {
String channelID = '';
int channelType = 0;
@ -41,26 +51,35 @@ class WKConversationMsgExtra {
int draftUpdatedAt = 0;
}
///
class WKUIConversationMsg {
int lastMsgSeq = 0;
String clientMsgNo = '';
//ID
/// ID
String channelID = '';
//
///
int channelType = 0;
//
///
int lastMsgTimestamp = 0;
//
///
WKChannel? _wkChannel;
//
///
WKMsg? _wkMsg;
//
///
int unreadCount = 0;
int isDeleted = 0;
WKConversationMsgExtra? _remoteMsgExtra;
//[{type:1,text:'[有人@你]'}]
/// [{type:1,text:'[有人@你]'}]
List<WKReminder>? _reminderList;
//
///
dynamic localExtraMap;
String parentChannelID = '';
int parentChannelType = 0;
@ -103,6 +122,7 @@ class WKUIConversationMsg {
}
}
///
class WKSyncConversation {
int cmdVersion = 0;
List<WkSyncCMD>? cmds;
@ -110,6 +130,7 @@ class WKSyncConversation {
List<WKSyncConvMsg>? conversations;
}
///
class WKSyncConvMsg {
String channelID = '';
int channelType = 0;

View File

@ -10,6 +10,7 @@ import '../type/const.dart';
import 'channel.dart';
import 'channel_member.dart';
///
class WKMsg {
MessageHeader header = MessageHeader();
Setting setting = Setting();

View File

@ -1,3 +1,4 @@
///
class WKReminder {
int reminderID = 0;
String messageID = '';
@ -15,6 +16,7 @@ class WKReminder {
String publisher = '';
}
///
class WKMentionType {
//@
static const int wkReminderTypeMentionMe = 1;

View File

@ -7,27 +7,11 @@ void main() {
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a blue toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
@ -38,16 +22,6 @@ class MyApp extends StatelessWidget {
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
@ -59,50 +33,19 @@ class _MyHomePageState extends State<MyHomePage> {
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
@ -119,7 +62,7 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
),
);
}
}

View File

@ -18,13 +18,30 @@ import 'model/wk_card_content.dart';
class WKIM {
WKIM._privateConstructor();
int deviceFlagApp = 0;
static final WKIM _instance = WKIM._privateConstructor();
static WKIM get shared => _instance;
///
int deviceFlagApp = 0;
/// 使
@Deprecated('Use Options deviceFlag')
void setDeviceFlag(int deviceFlag) {
deviceFlagApp = deviceFlag;
}
///
Model runMode = Model.app;
/// - APP
bool isApp() {
return runMode == Model.app;
}
///
Options options = Options();
///
Future<bool> setup(Options opts) async {
options = opts;
deviceFlagApp = opts.deviceFlag;
@ -39,6 +56,7 @@ class WKIM {
return true;
}
///
_initNormalMsgContent() {
messageManager.registerMsgContent(WkMessageContentType.text,
(dynamic data) {
@ -62,20 +80,24 @@ class WKIM {
});
}
@Deprecated('Use Options deviceFlag')
void setDeviceFlag(int deviceFlag) {
deviceFlagApp = deviceFlag;
}
bool isApp() {
return runMode == Model.app;
}
///
WKWebConnectionManager connectionManager = WKWebConnectionManager.shared;
///
WKMessageManager messageManager = WKMessageManager.shared;
///
WKConversationManager conversationManager = WKConversationManager.shared;
///
WKChannelManager channelManager = WKChannelManager.shared;
///
WKChannelMemberManager channelMemberManager = WKChannelMemberManager.shared;
///
WKReminderManager reminderManager = WKReminderManager.shared;
///
WKCMDManager cmdManager = WKCMDManager.shared;
}