ws_chat_flutter 1.0.2
ws_chat_flutter: ^1.0.2 copied to clipboard
A real-time chat widget for Flutter with AI support and Socket.IO, enabling smooth customer service handover.
π¬ WS Chat Flutter #
A comprehensive real-time chat widget package for Flutter with AI assistance and seamless customer service handover, built with Socket.IO.
β¨ Features #
π― Customer Chat Screen #
- π€ AI-Powered Responses - Instant automated replies using AI
- π€ Human CS Handover - Seamless transfer to human agents
- π± Responsive Design - Works on phones, tablets, and web
- π¬ Real-time Messaging - Instant message delivery
- β Read Receipts - Know when messages are read
- π Chat History - Persistent conversation history
- π¨ Customizable Theme - Adjust colors to match your brand
- π Auto-Reconnect - Handles connection drops gracefully
π¨βπΌ CS Dashboard Screen #
- π Multi-Chat Management - Handle multiple conversations
- π Real-time Updates - Instant message and status updates
- π€ AI Summary - View AI conversation summaries
- π Notifications - In-app notifications for new messages
- β Message Read Tracking - See when customers read messages
- π― Smart Sorting - Auto-sorted by latest activity
- π± Responsive Layout - Desktop and mobile optimized
π¦ Installation #
Add this to your package's pubspec.yaml file:
dependencies:
ws_chat_flutter: ^1.0.1
Then run:
flutter pub get
π Quick Start #
1. Customer Chat Screen #
import 'package:flutter/material.dart';
import 'package:ws_chat_flutter/ws_chat_flutter.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChatScreen(
serverUrl: 'https://your-server.com',
customerId: 'customer_123',
customerName: 'John Doe',
primaryColor: Color(0xFF4F46E5),
),
),
);
},
child: Text('Open Chat'),
),
),
),
);
}
}
2. CS Dashboard Screen #
import 'package:flutter/material.dart';
import 'package:ws_chat_flutter/ws_chat_flutter.dart';
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CSDashboardScreen(
serverUrl: 'https://your-server.com',
csUserId: 'cs_001',
csName: 'Agent Sarah',
primaryColor: Color(0xFF10B981),
),
),
);
π± Usage Examples #
Example 1: In-App Support Button #
import 'package:flutter/material.dart';
import 'package:ws_chat_flutter/ws_chat_flutter.dart';
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My App'),
actions: [
IconButton(
icon: Icon(Icons.support_agent),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChatScreen(
serverUrl: 'https://your-server.com',
customerId: 'user_123',
customerName: 'John Doe',
),
),
);
},
),
],
),
body: Center(
child: Text('Welcome to My App'),
),
);
}
}
Example 2: Bottom Navigation Integration #
import 'package:flutter/material.dart';
import 'package:ws_chat_flutter/ws_chat_flutter.dart';
class MainScreen extends StatefulWidget {
@override
_MainScreenState createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
int _currentIndex = 0;
final List<Widget> _screens = [
HomeScreen(),
ChatScreen(
serverUrl: 'https://your-server.com',
customerId: 'customer_123',
customerName: 'John Doe',
showBackButton: false,
),
ProfileScreen(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: _screens[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (index) => setState(() => _currentIndex = index),
items: [
BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
BottomNavigationBarItem(icon: Icon(Icons.chat), label: 'Support'),
BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'),
],
),
);
}
}
π¨ Customization #
Custom Colors #
ChatScreen(
serverUrl: 'https://your-server.com',
customerId: 'customer_123',
customerName: 'John Doe',
primaryColor: Color(0xFFFF6B6B), // Custom brand color
)
Custom Title #
ChatScreen(
serverUrl: 'https://your-server.com',
customerId: 'customer_123',
customerName: 'John Doe',
title: 'Talk to Us', // Custom title
)
Hide Back Button #
ChatScreen(
serverUrl: 'https://your-server.com',
customerId: 'customer_123',
customerName: 'John Doe',
showBackButton: false, // Useful for embedded screens
)
π§ Backend Requirements #
This package requires a Socket.IO server. Here's the event contract:
Customer Events (Client β Server) #
// Initialize chat
socket.emit('start_chat', {
customerId: 'customer_123',
customerName: 'John Doe',
initialMessage: 'Hello'
});
// Send message
socket.emit('customer_message', {
customerId: 'customer_123',
message: 'Hello',
chatRoomId: 'room_123'
});
// Get history
socket.emit('get_customer_chat_history', {
customerId: 'customer_123',
chatRoomId: 'room_123'
});
// Mark as read
socket.emit('mark_message_read', {
messageId: 'msg_123',
customerId: 'customer_123'
});
CS Events (Client β Server) #
// CS Login
socket.emit('cs_login', {
userId: 'cs_001',
name: 'Agent Sarah'
});
// Get rooms
socket.emit('cs_get_all_rooms', {
csUserId: 'cs_001'
});
// Select room
socket.emit('cs_select_room', {
chatRoomId: 'room_123',
csUserId: 'cs_001'
});
// Send message
socket.emit('cs_send_message', {
chatRoomId: 'room_123',
message: 'Hello',
csUserId: 'cs_001'
});
Server Events (Server β Client) #
// Chat started
socket.on('chat_started', (data) => {
// data: { chatRoomId, status, csName, message }
});
// New message
socket.on('receive_message', (data) => {
// data: { id, text, sender, timestamp, senderName }
});
// AI typing
socket.on('ai_typing', () => {});
// CS assigned
socket.on('cs_assigned', (data) => {
// data: { csName }
});
π± Platform Support #
| Platform | Supported |
|---|---|
| Android | β Yes |
| iOS | β Yes |
| Web | β Yes |
| macOS | β Yes |
| Windows | β Yes |
| Linux | β Yes |
π API Reference #
ChatScreen #
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
serverUrl |
String |
β | - | WebSocket server URL |
customerId |
String |
β | - | Unique customer identifier |
customerName |
String |
β | - | Customer display name |
title |
String? |
β | null | Custom screen title |
primaryColor |
Color? |
β | 0xFF4F46E5 |
Primary theme color |
showBackButton |
bool |
β | true |
Show/hide back button |
CSDashboardScreen #
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
serverUrl |
String |
β | - | WebSocket server URL |
csUserId |
String |
β | - | Unique CS agent identifier |
csName |
String |
β | - | CS agent display name |
primaryColor |
Color? |
β | 0xFF10B981 |
Primary theme color |
π Security Best Practices #
// β
DO: Use HTTPS in production
const serverUrl = 'https://api.example.com';
// β
DO: Use environment variables
const serverUrl = String.fromEnvironment('SERVER_URL');
// β DON'T: Hardcode credentials
// β DON'T: Use HTTP in production
π Troubleshooting #
Connection Issues #
Problem: Chat won't connect
Solution:
- Verify server URL is correct and accessible
- Ensure Socket.IO server is running
- Check CORS settings on server
- Enable debug mode to see connection logs
Messages Not Appearing #
Problem: Messages don't show up
Solution:
- Verify
customerId/csUserIdare unique - Check event names match your server implementation
- Ensure server emits proper response events
π€ Contributing #
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
π License #
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments #
- Built with socket_io_client
- Inspired by modern chat interfaces
- Thanks to the Flutter community
π Support #
- π Report bugs
- π¬ Discussions
- π§ Email: support@example.com
πΊοΈ Roadmap #
- β File upload support
- β Voice message support
- β Video call integration
- β Chat analytics
- β Multi-language support
- β Emoji picker
- β Message reactions
- β Push notifications
Made with β€οΈ using Flutter
