You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
open-im-sdk-flutter-m/example/lib/main.dart

80 lines
2.2 KiB

import 'package:flutter/material.dart';
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
void main() {
try {
runApp(const MyApp());
} catch (e, stackTrace) {
print('Error during app startup: $e');
print('Stack trace: $stackTrace');
}
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Future<void> send() async {
OpenIM.iMManager.messageManager
.sendMessage(
userID: "724f91aceb434a28a1cd10f5564b2c68",
message: await OpenIM.iMManager.messageManager
.createTextMessage(text: 'hello openim'),
offlinePushInfo: OfflinePushInfo(title: 'title', desc: 'desc'))
.then((value) {
print('send success');
}).catchError((error) {
print('send error');
});
}
@override
void initState() {
super.initState();
OpenIM.iMManager
.initSDK(
platformID: 3,
apiAddr: 'http://192.168.77.135:10002',
wsAddr: 'ws://192.168.77.135:10001',
dataDir: './',
listener: OnConnectListener())
.then((value) {});
OpenIM.iMManager.userManager.setUserListener(OnUserListener());
OpenIM.iMManager
.login(
userID: "8bfe13b5eac44e87963652abb91d80d2",
token:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOiI4YmZlMTNiNWVhYzQ0ZTg3OTYzNjUyYWJiOTFkODBkMiIsIlBsYXRmb3JtSUQiOjMsImV4cCI6MTc1NDM2NDkwNCwiaWF0IjoxNzQ2NTg4ODk5fQ.575xwR9lzJo1i5Te-Ul-99odONfxbzDXW0_2Kv3nFEE")
.then((value) {
List<String> list = [];
OpenIM.iMManager.userManager.subscribeUsersStatus(list);
send();
OpenIM.iMManager.conversationManager
.getAllConversationList()
.then((value) {
print('Get all conversation list successful');
});
}).catchError((error) {});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: [
TextButton(onPressed: () {}, child: const Text('login')),
],
),
),
);
}
}