Nexconn Infrastructure Engineer. Optimizes latency and scales microservices for hundreds of millions of concurrent users. Shares technical deep dives and backend lessons for zero-latency communication.
Building real-time messaging from scratch means handling connection lifecycles, offline synchronization, state management, and push notification edge cases. Most engineering teams prefer using a dedicated SDK so they can focus on their core product.
This guide walks you through integrating the Nexconn Flutter Chat SDK into a Flutter app from scratch. By following these steps, you will set up authentication, initialize the client, connect to the messaging cluster, and render a working conversation UI in about ten minutes.
What We Are Building
We will integrate the Nexconn Chat Flutter SDK and prebuilt UI components to achieve:
Client initialization with data center routing.
User authentication via token-based connection.
A functional channel list and conversation screen capable of sending real-time messages.
Developer Note: Nexconn provides a production-ready Chat Pro plan free up to 10,000 MAU (normally $860/month). To lock in this tier through 2027, you only need to integrate and use the Nexconn Chat SDK in your project.
Prerequisites
Before writing code, make sure you have:
Ensure your development environment meets the following specifications:
Flutter SDK: 3.29.2 or later (required by Chat UI Kit).
Dart SDK: Compatible with 3.9.2+ (Note: the core Chat SDK requires Dart ^3.7.2, but the prebuilt UI plugin requires Dart 3.9.2+).
Step 1: Create an App and Retrieve Your Credentials
To connect to Nexconn, you need an App Key for client configuration and a temporary User Token for authentication.
Log into the Nexconn Console. A default application is created automatically upon registration.
Under Chat Subscription, ensure the Chat Pro 10K promotional tier is selected.
In the application settings or dashboard, copy your App Key (default data center is set to Singapore).
Go to Application Information / App Key, scroll down to token testing, enter a test User ID (e.g., user_001), and click Get Token. Copy this token string for local testing.
Step 2: Add Dependencies to Your Flutter Project
Add both the Chat UI plugin and the core Chat plugin to your Flutter project:
Android: Open android/app/build.gradle. Ensure minSdkVersion is set to 21 or higher.
iOS: Open ios/Podfile. Ensure the deployment target is set to iOS 12.0 or higher:
platform :ios, '12.0'
Step 3: Initialize the Nexconn Engine
Because the prebuilt UI widgets depend on EngineProvider across the widget tree, you must instantiate EngineProvider and wrap your app with NexconnChatUIProviders inside main():
import 'package:flutter/material.dart';
import 'package:ai_nexconn_chatui_plugin/ai_nexconn_chatui_plugin.dart';
import 'package:ai_nexconn_chat_plugin/ai_nexconn_chat_plugin.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
const String appKey = 'YOUR_APP_KEY_HERE';
final initParams = InitParams(
appKey: appKey,
areaCode: AreaCode.SG, // Default Singapore data center
);
// 1. Instantiate and initialize EngineProvider
final engineProvider = EngineProvider();
await engineProvider.initialize(initParams);
// 2. Wrap your application with NexconnChatUIProviders
runApp(
NexconnChatUIProviders(
engineProvider: engineProvider,
child: const MyApp(),
),
);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: ChatHomeScreen(),
);
}
}
Step 4: Authenticate and Establish Connection
In production, your client app queries your backend server to receive a signed user token. For this quickstart, use the token generated in the console during Step 1.
Call NCEngine.connect() to open the persistent socket connection:
class ChatHomeScreen extends StatefulWidget {
const ChatHomeScreen({super.key});
@override
State<ChatHomeScreen> createState() => _ChatHomeScreenState();
}
class _ChatHomeScreenState extends State<ChatHomeScreen> {
bool _isConnected = false;
String _statusText = 'Disconnected';
@override
void initState() {
super.initState();
_connect();
}
Future<void> _connect() async {
const String testToken = 'YOUR_TEST_TOKEN_FROM_CONSOLE';
final connectParams = ConnectParams(token: testToken);
// Read the EngineProvider initialized in main() from the widget tree.
final engineProvider = context.read<EngineProvider>();
// Use the standard single-callback handler to process the connection result.
await engineProvider.connect(
connectParams,
handler: (String? userId, NCError? error) {
// On success, the SDK returns a userId together with NCError(code: 0),
// so check error?.isSuccess instead of error == null.
if (error?.isSuccess == true && userId != null) {
setState(() {
_isConnected = true;
_statusText = 'Connected as: $userId';
});
debugPrint('Connected successfully as: $userId');
} else {
setState(() {
_statusText = 'Connection failed: ${error?.message ?? 'Unknown error'}';
});
debugPrint('Connection error: ${error?.code} - ${error?.message}');
}
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Nexconn Chat Demo')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(_statusText),
const SizedBox(height: 24),
ElevatedButton(
onPressed: _isConnected ? _navigateToChannelPage : null,
child: const Text('Open Conversation Screen'),
),
],
),
),
);
}
void _navigateToChannelPage() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const ChannelPage(),
),
);
}
}
Step 5: Run the App and Send Your First Message
Start your application on an emulator or connected device:
flutter run
Then verify the flow:
The connection status should update to Connected as: user_001.
Tap Open Conversation Screen to mount the default prebuilt ChannelPage.
If the channel list is empty (expected for a brand-new test user), create a direct channel from another test account to user_001, or mount ChannelPage with an initialChannels list.
Open the channel, type a message or send an emoji, and press Send.
Production Architecture Considerations
Before deploying this to production, keep these operational requirements in mind:
Keep Secrets on Your Backend: Never bundle your App Secret inside client-side Flutter code. Your backend must call Nexconn's REST API using the secret to generate user tokens, returning only the token to the authenticated mobile user.
Handle Multi-Channel Push: For background notifications on iOS and Android when the app is suspended, configure APNs certificates and Firebase Cloud Messaging (FCM) credentials in the Nexconn console.
Network Resilience: The SDK includes automatic reconnection and offline delta sync. When network connectivity drops, messages queue locally and synchronize once the socket re-establishes.
Next Steps
You now have a fully functional real-time chat pipeline operating inside your Flutter application.
Add rich media attachments, typing indicators, and read receipts.
Set up webhooks on your server to sync messaging events with your CRM or moderation pipeline.
Contact us
We'd love to discuss how Nexconn's real-time communication solutions can support your business. Request a demo, explore pricing, or get tailored onboarding guidance.