Build ChatGPT-style chat interfaces in Flutter. Simple to use, easy to customize.
Dark Mode |
Chat Demo |
Need help integrating this package with your specific use case? Copy this prompt into ChatGPT:
Help me integrate flutter_gen_ai_chat_ui with my Flutter app.
My app details:
1. App type: [e.g., AI chatbot, customer support, education app]
2. Backend: [e.g., OpenAI API, custom API, Firebase]
3. Features needed: [e.g., streaming responses, markdown support, dark mode]
4. Current state management: [e.g., Provider, Bloc, GetX]
Please show me:
1. How to integrate the chat UI
2. How to connect it with my backend
3. How to customize the theme to match my app
4. Best practices for my specific use case
The AI will provide:
- โ Complete integration code
- โ Backend connection setup
- โ Theme customization examples
- โ Performance optimization tips
- โ Use case specific recommendations
- ๐จ Dark and light mode support
- ๐ซ Smooth message animations
- ๐ Word-by-word text streaming (like ChatGPT)
- โจ Loading indicators with shimmer effect
- ๐ฑ Responsive layout for all screen sizes
- ๐ Markdown support with syntax highlighting
- ๐ฏ Selectable text in messages
- ๐ Clickable links
- ๐ Message pagination
- ๐ RTL language support
- ๐ Customizable welcome message
- โญ๏ธ Example questions widget
- ๐ฌ Custom message bubbles
- ๐ฎ Custom input field and send button
dependencies:
flutter_gen_ai_chat_ui: ^1.1.2
import 'package:flutter_gen_ai_chat_ui/flutter_gen_ai_chat_ui.dart';
import 'package:dash_chat_2/dash_chat_2.dart';
Here's a simple chat screen:
class ChatScreen extends StatefulWidget {
@override
State<ChatScreen> createState() => _ChatScreenState();
}
class _ChatScreenState extends State<ChatScreen> {
late final _controller = ChatMessagesController();
late final _currentUser = ChatUser(id: '1', firstName: 'User');
late final _aiUser = ChatUser(id: '2', firstName: 'AI Assistant');
bool _isLoading = false;
Future<void> _handleSendMessage(ChatMessage message) async {
setState(() => _isLoading = true);
_controller.addMessage(message);
try {
// Add your AI response logic here
final response = ChatMessage(
text: "Hello! I received: ${message.text}",
user: _aiUser,
createdAt: DateTime.now(),
);
_controller.addMessage(response);
} finally {
setState(() => _isLoading = false);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('AI Chat')),
body: AiChatWidget(
config: AiChatConfig(
hintText: 'Type a message...',
enableAnimation: true,
),
controller: _controller,
currentUser: _currentUser,
aiUser: _aiUser,
onSendMessage: _handleSendMessage,
isLoading: _isLoading,
),
);
}
}
Theme(
data: Theme.of(context).copyWith(
extensions: [
CustomThemeExtension(
// Message colors
messageBubbleColor: isDark ? Color(0xFF262626) : Colors.white,
userBubbleColor: isDark ? Color(0xFF1A4B8F) : Color(0xFFE3F2FD),
messageTextColor: isDark ? Color(0xFFE5E5E5) : Colors.grey[800]!,
// Input field colors
inputBackgroundColor: isDark ? Color(0xFF262626) : Colors.white,
inputBorderColor: isDark ? Color(0xFF404040) : Colors.grey[300]!,
// Background and accent colors
chatBackground: isDark ? Color(0xFF171717) : Colors.grey[50]!,
sendButtonIconColor: isDark ? Color(0xFF60A5FA) : Colors.blue,
),
],
),
child: AiChatWidget(...),
)
Future<void> handleStreamingResponse(ChatMessage message) async {
final response = ChatMessage(
text: "",
user: aiUser,
createdAt: DateTime.now(),
);
controller.addMessage(response);
// Simulate streaming response
final words = "Hello! How can I help you today?".split(' ');
String currentText = '';
for (var word in words) {
await Future.delayed(Duration(milliseconds: 50));
currentText += (currentText.isEmpty ? '' : ' ') + word;
controller.messages.removeWhere((m) =>
m.createdAt == response.createdAt && m.user.id == aiUser.id
);
controller.addMessage(ChatMessage(
text: currentText,
user: aiUser,
createdAt: response.createdAt,
));
}
}
AiChatConfig(
messageBuilder: (message) => MarkdownBody(
data: message.text,
styleSheet: MarkdownStyleSheet(
p: TextStyle(color: Colors.white),
code: TextStyle(backgroundColor: Colors.grey[800]),
h1: TextStyle(color: Colors.white, fontSize: 24),
),
),
)
Check out our example folder for complete implementations:
- Streaming Example: Word-by-word text streaming like ChatGPT
- Custom Styling: Dark/light mode with beautiful UI
- Markdown Support: Rich text formatting in messages
- ๐ Check our example folder
- ๐ File issues on our GitHub repository
- ๐ก Contribute to the project
MIT License - see the LICENSE file for details.