paanj_chat_client 0.0.2 copy "paanj_chat_client: ^0.0.2" to clipboard
paanj_chat_client: ^0.0.2 copied to clipboard

Chat Client SDK for Paanj platform. Provides real-time messaging, conversation management, and user presence.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:paanj_client/paanj_client.dart';
import 'package:paanj_chat_client/paanj_chat_client.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Paanj Chat Example',
      home: const ChatScreen(),
    );
  }
}

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

  @override
  State<ChatScreen> createState() => _ChatScreenState();
}

class _ChatScreenState extends State<ChatScreen> {
  late PaanjClient client;
  late ChatClient chatClient;
  bool _isAuthenticated = false;
  List<Conversation> _conversations = [];

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

  Future<void> _initPaanj() async {
    // Replace with your public key
    const publicKey = 'YOUR_PUBLIC_KEY';

    client = PaanjClient(publicKey,
        options: ClientOptions(
          apiKey: publicKey,
          apiUrl: 'https://api.paanj.com',
          wsUrl: 'wss://ws.paanj.com',
        ));
    chatClient = ChatClient(client);

    try {
      // Authenticate anonymously for demo
      await client.authenticateAnonymous({'name': 'Example User'});
      await client.connect();

      setState(() {
        _isAuthenticated = true;
      });

      _loadConversations();
    } catch (e) {
      debugPrint('Error initializing Paanj: $e');
    }
  }

  Future<void> _loadConversations() async {
    if (!_isAuthenticated) return;
    try {
      final conversations = await chatClient.listConversations();
      setState(() {
        _conversations = conversations;
      });
    } catch (e) {
      debugPrint('Error loading conversations: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Paanj Chat Example')),
      body: !_isAuthenticated
          ? const Center(child: CircularProgressIndicator())
          : ListView.builder(
              itemCount: _conversations.length,
              itemBuilder: (context, index) {
                final conversation = _conversations[index];
                return ListTile(
                  title: Text(conversation.name ?? 'Untitled Chat'),
                  subtitle: Text(conversation.id),
                );
              },
            ),
      floatingActionButton: FloatingActionButton(
        onPressed: _loadConversations,
        child: const Icon(Icons.refresh),
      ),
    );
  }

  @override
  void dispose() {
    client.disconnect();
    super.dispose();
  }
}
0
likes
140
points
16
downloads

Documentation

API reference

Publisher

verified publisherpaanj.com

Weekly Downloads

Chat Client SDK for Paanj platform. Provides real-time messaging, conversation management, and user presence.

Homepage
Repository (GitHub)
View/report issues

Topics

#chat #sdk #messaging #realtime #websocket

License

MIT (license)

Dependencies

flutter, paanj_client

More

Packages that depend on paanj_chat_client