flutter_chat_package_dev 0.0.1 copy "flutter_chat_package_dev: ^0.0.1" to clipboard
flutter_chat_package_dev: ^0.0.1 copied to clipboard

A chat Flutter package project. MIT

Flutter Chat Package Dev #

A feature-rich Flutter chat package that provides real-time messaging, push notifications, and offline support.

Features #

  • Real-time messaging with WebSocket support
  • Push notifications for new messages
  • Offline message storage and synchronization
  • Group and one-to-one chat support
  • Read receipts and typing indicators
  • Image and file sharing capabilities
  • Customizable UI components

Installation #

Add the following dependencies to your app's pubspec.yaml:

dependencies:
  flutter_chat_package_dev: ^1.0.0  # Use the latest version
  web_socket_channel: ^2.4.0
  shared_preferences: ^2.2.2
  sqflite: ^2.3.0
  path_provider: ^2.1.1
  firebase_messaging: ^14.7.10
  flutter_local_notifications: ^16.3.2
  provider: ^6.1.1
  intl: ^0.18.1
  http: ^1.1.0
  connectivity_plus: ^5.0.2
  internet_connection_checker: ^1.0.0+1

Setup #

Android Configuration #

  1. Add internet permission to android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<application
    android:hardwareAccelerated="true">
</application>

  1. For Firebase Cloud Messaging, add your google-services.json to android/app/.

  2. Add DESUGAR JDK to android/app/build.gradle.

dependencies {
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3' 
}
android {
    compileOptions {
        coreLibraryDesugaringEnabled true
    }
}

iOS Configuration #

  1. Add these to your ios/Runner/Info.plist:
<key>UIBackgroundModes</key>
<array>
    <string>remote-notification</string>
    <string>fetch</string>
</array>

<key>NSPhotoLibraryUsageDescription</key>
<string>Need photo library access to upload images</string>
<key>NSCameraUsageDescription</key>
<string>Need camera access to take pictures</string>
<key>NSMicrophoneUsageDescription</key>
<string>Need microphone access for voice messages</string>
  1. For Firebase, add your GoogleService-Info.plist to ios/Runner/.

Initialization #

1. Main App Setup #

Wrap your main app with required providers:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  // Init Chat SQlite DB
  await ChatDatabase.init();
  
  // Initialize notification services
  await ChatNotifications.initializeServices();
  
  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => ChatProvider()),
      ],
      child: const MyApp(),
    ),
  );
}

2. Initialize Chat in Your Root Widget #

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    _initializeChat();
  }

  Future<void> _initializeChat() async {
    // Initialize chat notifications with context
    ChatNotifications.init(context);
  }
}

3. Clear Chat Database #

Inside Signout or any other function where you want to clear the chat database

await ChatDatabase.deleteDatabase();

4. Using the Chat #

Start Chat Feature


if (mounted) {
  Navigator.push(
    context,
    MaterialPageRoute( 
        builder: (_) =>
        ChatEntry(
            baseUrl: const String.fromEnvironment('CHAT_BASE_URL'),
            socketUrl: const String.fromEnvironment('CHAT_SOCKET_URL'),
            accessToken: prefs.get('IAMtoken') as String? ?? '',
            user: prefs.get('user_id') as String? ?? '',
            appId: const String.fromEnvironment('CHAT_APP_ID'),
            subAppId: const String.fromEnvironment('CHAT_SUB_APP_ID'),
            initialPage: EntryPage.chatList,
            conversation: ConversationModel(chatName: '', conversationId: ''),
            onTokenRefresh: () async {
            return refreshTokenForChat();
            },
        ),
    ),
  );
}

Additional Information #

Error Handling #

  • The package handles most errors internally and shows appropriate error messages
  • Network connectivity issues are automatically managed with retry mechanisms
  • Failed messages are queued and sent when back online

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

Reporting Issues #

Please file any issues, bugs, or feature requests in the GitHub repository.

License #

This project is licensed under the MIT License - see the LICENSE file for details.