flutter_chat_sdk 0.1.0+1 copy "flutter_chat_sdk: ^0.1.0+1" to clipboard
flutter_chat_sdk: ^0.1.0+1 copied to clipboard

A backend-agnostic Flutter chat SDK with offline-first support, real-time sync, and a persistent outbound queue that survives app restarts. Bring your own backend via the ChatAdapter interface.

example/lib/main.dart

// example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:chat/chat.dart';
import 'package:chat/testing.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  final chat = await Chat.create(
    databasePath: ':memory:',
    adapter: MockChatAdapter(),
    identityProvider: const StaticIdentityProvider('user-1'),
  );

  await chat.connect();

  // Seed a demo conversation
  final adapter = chat.registry.adapter as MockChatAdapter;
  adapter.simulateIncomingMessage(
    conversationId: 'demo',
    senderId: 'user-2',
    content: 'Hello from the example!',
  );

  runApp(ChatExampleApp(chat: chat));
}

class ChatExampleApp extends StatelessWidget {
  const ChatExampleApp({super.key, required this.chat});
  final Chat chat;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Chat SDK Example',
      home: ConversationListScreen(chat: chat),
    );
  }
}

class ConversationListScreen extends StatelessWidget {
  const ConversationListScreen({super.key, required this.chat});
  final Chat chat;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Conversations')),
      body: StreamBuilder<List<Conversation>>(
        stream: chat.watchConversations(),
        builder: (context, snapshot) {
          if (!snapshot.hasData) {
            return const Center(child: CircularProgressIndicator());
          }
          final conversations = snapshot.data!;
          if (conversations.isEmpty) {
            return const Center(child: Text('No conversations yet.'));
          }
          return ListView.builder(
            itemCount: conversations.length,
            itemBuilder: (context, index) {
              final conversation = conversations[index];
              return ListTile(
                title: Text(conversation.displayName),
                subtitle: Text(
                  conversation.lastMessage?.displayText ?? 'No messages',
                ),
                trailing: conversation.hasUnread
                    ? Badge(label: Text('${conversation.unreadCount}'))
                    : null,
              );
            },
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => chat.sendMessage(
          conversationId: 'demo',
          content: 'Hello! ${DateTime.now()}',
        ),
        child: const Icon(Icons.send),
      ),
    );
  }
}
2
likes
140
points
125
downloads

Documentation

API reference

Publisher

verified publisherkaffah.dev

Weekly Downloads

A backend-agnostic Flutter chat SDK with offline-first support, real-time sync, and a persistent outbound queue that survives app restarts. Bring your own backend via the ChatAdapter interface.

Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

collection, drift, equatable, flutter, intl, meta, path, path_provider, sqlite3, uuid

More

Packages that depend on flutter_chat_sdk