ex_im_flutter_chat 0.0.8 copy "ex_im_flutter_chat: ^0.0.8" to clipboard
ex_im_flutter_chat: ^0.0.8 copied to clipboard

A Flutter plugin for enterprise instant messaging - provides complete IM functionality including messaging, friends, groups, and conversations.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:ex_im_flutter_chat/ex_im_flutter_chat.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  ExImChatState _sdkState = ExImChatState.uninitialized;

  @override
  void initState() {
    super.initState();
    _initSdk();
  }

  Future<void> _initSdk() async {
    // 监听 SDK 状态变化
    ExImChat.instance.stateStream.listen((state) {
      setState(() {
        _sdkState = state;
      });
    });

    // 初始化 SDK(只需 tenantId)
    try {
      await ExImChat.instance.init(
        tenantId: '7408435945185349631',
        environment: 'dev',
      );
    } catch (e) {
      debugPrint('SDK 初始化失败: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('ExIm Chat Example'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('SDK State: $_sdkState'),
              const SizedBox(height: 20),
              if (_sdkState == ExImChatState.initialized)
                ElevatedButton(
                  onPressed: _login,
                  child: const Text('Login'),
                ),
              if (_sdkState == ExImChatState.loggedIn)
                ElevatedButton(
                  onPressed: _connect,
                  child: const Text('Connect Socket'),
                ),
              if (_sdkState == ExImChatState.connected)
                ElevatedButton(
                  onPressed: _logout,
                  child: const Text('Logout'),
                ),
            ],
          ),
        ),
      ),
    );
  }

  Future<void> _login() async {
    try {
      await ExImChat.instance.loginWithEmail(
        email: 'test@example.com',
        password: 'password123',
      );
    } catch (e) {
      debugPrint('登录失败: $e');
    }
  }

  Future<void> _connect() async {
    try {
      await ExImChat.instance.connect();
    } catch (e) {
      debugPrint('连接失败: $e');
    }
  }

  Future<void> _logout() async {
    try {
      await ExImChat.instance.logout();
    } catch (e) {
      debugPrint('退出登录失败: $e');
    }
  }
}
1
likes
125
points
301
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for enterprise instant messaging - provides complete IM functionality including messaging, friends, groups, and conversations.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

asn1lib, cached_network_image, dio, encrypt, flutter, flutter_cache_manager, flutter_screenutil, hive, hive_flutter, path, path_provider, pointycastle, socket_io_client, uuid

More

Packages that depend on ex_im_flutter_chat

Packages that implement ex_im_flutter_chat