{"id":19614802,"url":"https://github.com/leancloud/realtime-sdk-flutter","last_synced_at":"2025-04-28T01:32:21.445Z","repository":{"id":44923182,"uuid":"229027800","full_name":"leancloud/Realtime-SDK-Flutter","owner":"leancloud","description":"LeanCloud Flutter Plugin SDK","archived":false,"fork":false,"pushed_at":"2022-11-28T10:03:58.000Z","size":6378,"stargazers_count":26,"open_issues_count":2,"forks_count":10,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-05T05:03:27.655Z","etag":null,"topics":["android","flutter","ios","leancloud","realtime-messaging","sdk"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leancloud.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-19T10:09:55.000Z","updated_at":"2023-12-30T05:17:07.000Z","dependencies_parsed_at":"2022-09-22T17:31:59.664Z","dependency_job_id":null,"html_url":"https://github.com/leancloud/Realtime-SDK-Flutter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2FRealtime-SDK-Flutter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2FRealtime-SDK-Flutter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2FRealtime-SDK-Flutter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2FRealtime-SDK-Flutter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leancloud","download_url":"https://codeload.github.com/leancloud/Realtime-SDK-Flutter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251234171,"owners_count":21556792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","flutter","ios","leancloud","realtime-messaging","sdk"],"created_at":"2024-11-11T10:53:49.429Z","updated_at":"2025-04-28T01:32:18.235Z","avatar_url":"https://github.com/leancloud.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# leancloud_official_plugin\n\nAn official flutter plugin for [LeanCloud](https://www.leancloud.cn) real-time message service based on [LeanCloud-Swift-SDK](https://github.com/leancloud/swift-sdk) and [LeanCloud-Java-SDK](https://github.com/leancloud/java-unified-sdk).\n\n## Flutter Getting Started\n\nThis project is a starting point for a Flutter [plug-in package](https://flutter.dev/docs/development/packages-and-plugins),\na specialized package that includes platform-specific implementation code for Android and iOS.\n\nFor help getting started with Flutter, \nview [online documentation](https://flutter.dev/docs), \nwhich offers tutorials, samples, guidance on mobile development, and a full API reference.\n\n## Usage\n\n### Adding dependency\n\n1. Following this [document](https://flutter.dev/docs/development/packages-and-plugins/using-packages) to add **leancloud_official_plugin** to your app, like this:\n\n    ```\n    dependencies:\n      leancloud_official_plugin: '\u003e=x.y.z \u003c(x+1).0.0'    # Recommend using up-to-next-major policy.\n    ```\n\n2. Using [Gradle](https://gradle.org/) and [CocoaPods](https://cocoapods.org) to add platform-specific dependencies.\n\n    * Using *CocoaPods* in *terminal*\n      * do `$ cd ios/` \n      * then `$ pod update` or `$ pod install --repo-update`\n    * *Gradle*\n      * [reference](https://leancloud.cn/docs/sdk_setup-java.html#hash260111001)\n\n### Initialization\n\n1. import `package:leancloud_official_plugin/leancloud_plugin.dart` in `lib/main.dart` of your project, like this:\n    ```dart\n    import 'package:leancloud_official_plugin/leancloud_plugin.dart';\n    ```\n\n2. import `cn.leancloud.LeanCloud`, `cn.leancloud.LCLogger` and `cn.leancloud.im.LCIMOptions` in `YourApplication.java` of your project, then set up ***ID***, ***Key*** and ***URL***, like this:\n    ```java\n    import io.flutter.app.FlutterApplication;\n    import cn.leancloud.LeanCloud;\n    import cn.leancloud.LCLogger;\n    import cn.leancloud.im.LCIMOptions;\n\n    public class YourApplication extends FlutterApplication {\n      @Override\n      public void onCreate() {\n        super.onCreate();\n        LCIMOptions.getGlobalOptions().setUnreadNotificationEnabled(true);\n        LeanCloud.setLogLevel(LCLogger.Level.DEBUG);\n        LeanCloud.initialize(this, YOUR_LC_APP_ID, YOUR_LC_APP_KEY, YOUR_LC_SERVER_URL);\n      }\n    }\n    ```\n\n3. import `LeanCloud` in `AppDelegate.swift` of your project, then set up ***ID***, ***Key*** and ***URL***, like this:\n    ```swift\n    import Flutter\n    import LeanCloud\n\n    @UIApplicationMain\n    @objc class AppDelegate: FlutterAppDelegate {\n        override func application(\n            _ application: UIApplication,\n            didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?\n        ) -\u003e Bool {\n            do {\n                LCApplication.logLevel = .all\n                try LCApplication.default.set(\n                    id: YOUR_LC_APP_ID,\n                    key: YOUR_LC_APP_KEY,\n                    serverURL: YOUR_LC_SERVER_URL)\n                GeneratedPluginRegistrant.register(with: self)\n                return super.application(application, didFinishLaunchingWithOptions: launchOptions)\n            } catch {\n                fatalError(\"\\(error)\")\n            }\n        }\n    }\n    ```\n\n### Push setup (optional)\n\nDue to different push service in iOS and Android, the setup-code should be wrote in native platform. \nit's optional, so if you no need of push service, you can ignore this section.\n\n* iOS\n\n    ```swift\n    import Flutter\n    import LeanCloud\n    import UserNotifications\n\n    @UIApplicationMain\n    @objc class AppDelegate: FlutterAppDelegate {\n        override func application(\n            _ application: UIApplication,\n            didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?\n        ) -\u003e Bool {\n            do {\n                LCApplication.logLevel = .all\n                try LCApplication.default.set(\n                    id: YOUR_LC_APP_ID,\n                    key: YOUR_LC_APP_KEY,\n                    serverURL: YOUR_LC_SERVER_URL)\n                GeneratedPluginRegistrant.register(with: self)\n                /*\n                register APNs to access token, like this:\n                */ \n                UNUserNotificationCenter.current().getNotificationSettings { (settings) in\n                    switch settings.authorizationStatus {\n                    case .authorized:\n                        DispatchQueue.main.async {\n                            UIApplication.shared.registerForRemoteNotifications()\n                        }\n                    case .notDetermined:\n                        UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert, .sound]) { (granted, error) in\n                            if granted {\n                                DispatchQueue.main.async {\n                                    UIApplication.shared.registerForRemoteNotifications()\n                                }\n                            }\n                        }\n                    default:\n                        break\n                    }\n                }\n                return super.application(application, didFinishLaunchingWithOptions: launchOptions)\n            } catch {\n                fatalError(\"\\(error)\")\n            }\n        }\n        \n        override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {\n            super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)\n            /*\n            set APNs deviceToken and Team ID.\n            */\n            LCApplication.default.currentInstallation.set(\n                deviceToken: deviceToken,\n                apnsTeamId: YOUR_APNS_TEAM_ID)\n            /*\n            save to LeanCloud.\n            */\n            LCApplication.default.currentInstallation.save { (result) in\n                switch result {\n                case .success:\n                    break\n                case .failure(error: let error):\n                    print(error)\n                }\n            }\n        }\n\n        override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {\n            super.application(application, didFailToRegisterForRemoteNotificationsWithError: error)\n            print(error)\n        }\n    }\n    ```\n\n* Android \n\n    [reference](https://leancloud.cn/docs/android_push_guide.html)\n\n## Sample Code\n\nAfter initialization, you can write some sample code and run it to check whether initializing success, like this:\n\n### Open\n\n```dart\n// new an IM client\nClient client = Client(id: CLIENT_ID);\n// open it\nawait client.open();\n```\n\n### Query Conversations\n\n```dart\n// the ID of the conversation instance list\nList\u003cString\u003e objectIDs = [...];\n// new query from an opened client\nConversationQuery query = client.conversationQuery();\n// set query condition\nquery.whereContainedIn(\n  'objectId',\n  objectIDs,\n);\nquery.limit = objectIDs.length;\n// do the query\nList\u003cConversation\u003e conversations = await query.find();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Frealtime-sdk-flutter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleancloud%2Frealtime-sdk-flutter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Frealtime-sdk-flutter/lists"}