A Flutter plugin for Zalo APIs.
Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!
To access Zalo APIs, you'll need to make sure to create your application.
Then, you access to Dashboard (https://developers.zalo.me/app/[ZaloAppID]/settings). Remember your ZaloAppID
To use this plugin, follow the plugin installation instructions.
android/app/build.gradle
and editminSdkVersion 21 // or bigger
/android/app/src/main/AndroidManifest.xml
and edit<application
...
android:name=".MyApplication">
<activity
...
android:name=".MainActivity">
...
</activity>
...
<!-- ZaloFlutter start -->
<meta-data
android:name="com.zing.zalo.zalosdk.appID"
android:value="@string/zalo_flutter_app_id" />
<activity
android:name="com.zing.zalo.zalosdk.oauth.BrowserLoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="@string/zalo_flutter_app_id_protocol"/>
</intent-filter>
</activity>
<!-- ZaloFlutter end -->
</application>
...
<!-- ZaloFlutter start -->
<queries>
<package android:name="com.zing.zalo" />
</queries>
<!-- ZaloFlutter end -->
strings.xml
(if not exists) on folder /android/app/src/main/res/values/strings.xml
. Replace with your ZaloAppID<resources>
<string name="zalo_flutter_app_id">[ZaloAppID]</string>
<string name="zalo_flutter_app_id_protocol">zalo-[ZaloAppID]</string>
</resources>
main.dart
and add this widget to get HashKey const ZaloHashKeyAndroid(),
Then, you build app and copy HashKey
Paste HashKey and YourPackageName to this page and press Save
NOTE: If you upload file .aab to Google Store, it will generate another HashKey, copy it to Dashboard.
-keep class com.zing.zalo.**{ *; }
-keep enum com.zing.zalo.**{ *; }
-keep interface com.zing.zalo.**{ *; }
MainActivity.kt
as below. Remember YourPackageNamepackage [YourPackageName]
import io.flutter.embedding.android.FlutterActivity
import android.content.Intent // <-- Add this line
import com.zing.zalo.zalosdk.oauth.ZaloSDK // <-- Add this line
class MainActivity: FlutterActivity() {
override fun onActivityResult(requestCode:Int, resultCode:Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
ZaloSDK.Instance.onActivityResult(this, requestCode, resultCode, data) // <-- Add this line
}
}
MyApplication.kt
in same folder of MainActivity.kt
. Replace with your YourPackageNamepackage [YourPackageName]
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import com.zing.zalo.zalosdk.oauth.ZaloSDKApplication
class MyApplication : FlutterApplication(), PluginRegistry.PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
ZaloSDKApplication.wrap(this)
}
override fun registerWith(registry: PluginRegistry) {}
}
MainActivity.java
as below. Remember YourPackageNamepackage [YourPackageName];
import io.flutter.embedding.android.FlutterActivity;
import androidx.annotation.NonNull; // <-- Add this line
import io.flutter.embedding.engine.FlutterEngine; // <-- Add this line
import io.flutter.plugins.GeneratedPluginRegistrant; // <-- Add this line
import android.content.Intent; // <-- Add this line
import com.zing.zalo.zalosdk.oauth.ZaloSDK; // Add this line
public class MainActivity extends FlutterActivity {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ZaloSDK.Instance.onActivityResult(this, requestCode, resultCode, data); // Add this line
}
}
MyApplication.java
in same folder of MainActivity.java
. Replace with your YourPackageNamepackage [YourPackageName]
import android.app.Application;
import com.zing.zalo.zalosdk.oauth.ZaloSDKApplication;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
ZaloSDKApplication.wrap(this);
}
}
ios/Runner/Info.plist
file, edit and replace with your ZaloAppID<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
...
<!-- ZaloFlutter start-->
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>zalo</string>
<key>CFBundleURLSchemes</key>
<array>
<string>zalo-[ZaloAppID]</string>
</array>
</dict>
</array>
<key>ZaloAppID</key>
<string>[ZaloAppID]</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>zalosdk</string>
<string>zaloshareext</string>
</array>
<!-- ZaloFlutter end-->
</dict>
</plist>
ios/Runner/AppDelegate.swift
file, add the following Zalo function code
import UIKit
import Flutter
import ZaloSDK // Add this line
@UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } // Zalo function go here override func application( app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { return ZDKApplicationDelegate.sharedInstance().application(app, open: url, options: options) } }
3. Open `ios/Runner.xcodeproj/project.pbxproj`, search `PRODUCT_BUNDLE_IDENTIFIER` and copy your **BundleID**
4. Open Zalo Dashboard => Login => IOS (https://developers.zalo.me/app/[ZaloAppID]/login)
Paste **BundleID** to this page and press **Save**
![](readme_assets/7.png)
## Usage
Add the following import to your Dart code:
```dart
import 'package:zalo_flutter/zalo_flutter.dart';
Functions:
String? data = await ZaloFlutter.getHashKeyAndroid();
ZaloLogin data = await ZaloFlutter.login(
refreshToken: refreshToken,
);
await ZaloFlutter.logout();
bool data = await ZaloFlutter.validateRefreshToken(
refreshToken: refreshToken,
);
ZaloProfile data = await ZaloFlutter.getUserProfile(
accessToken: accessToken,
);
Pham Tien Dung
If you have any questions, feel free to message me right away
Gmail: tiendung01023@gmail.com
Github: https://github.com/tiendung01023