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.
- Open
android/app/build.gradle
and edit
minSdkVersion 18 // or bigger
- Open to
/android/app/src/main/AndroidManifest.xml
and edit
<application
...
android:name=".MyApplication">
<activity
...
android:name=".MainActivity">
...
</activity>
...
<!-- ZaloFlutter -->
<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">
<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>
</application>
- Create file
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>
- Open file
main.dart
and add this function to get HashKey
@override
void initState() {
super.initState();
_initZaloFlutter(); // Add this line
}
// Add this function
Future<void> _initZaloFlutter() async {
if (Platform.isAndroid) {
final hashKey = await ZaloFlutter.getHashKeyAndroid();
log('HashKey: $hashKey');
}
}
Then, you see Debug console and copy HashKey
- Open Zalo Dashboard => Login => Android (https://developers.zalo.me/app/[ZaloAppID]/login)
Paste HashKey and YourPackageName to this page and press Save
- Edit the file
MainActivity.kt
as below. Remember YourPackageName
package [YourPackageName]
import android.content.Intent
import io.flutter.embedding.android.FlutterActivity
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
}
}
- Create file
MyApplication.kt
in same folder ofMainActivity.kt
. Replace with your YourPackageName
package [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) {}
}
- Edit the file
MainActivity.java
as below. Remember YourPackageName
package [YourPackageName];
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
import android.content.Intent;
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
}
}
- Create file
MyApplication.java
in same folder ofMainActivity.java
. Replace with your YourPackageName
package [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);
}
}
- Open
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>
<!-- ZaloFlutter end-->
</dict>
</plist>
-
Open
ios/Runner.xcodeproj/project.pbxproj
, searchPRODUCT_BUNDLE_IDENTIFIER
and copy your BundleID -
Open Zalo Dashboard => Login => IOS (https://developers.zalo.me/app/[ZaloAppID]/login) Paste BundleID to this page and press Save
Add the following import to your Dart code:
import 'package:zalo_flutter/zalo_flutter.dart';
Functions:
- Get HashKey Android for register app in dashboard Zalo
String? data = await ZaloFlutter.getHashKeyAndroid();
- Authenticate (with app or webview)
ZaloLogin data = await ZaloFlutter.login();
- Check if authenticated
bool data = await ZaloFlutter.isLogin();
- Log out - SDK clear oauth code in cache
await ZaloFlutter.logout();
- Get Zalo user profile
ZaloProfile data = await ZaloFlutter.getUserProfile();
- Get Zalo user friend list (used app)
ZaloUserFriend data = await ZaloFlutter.getUserFriendList();
- Get Zalo user friend list (not used app)
ZaloUserFriend data = await ZaloFlutter.getUserInvitableFriendList();
- Send message to a friend
ZaloSendMessage data = await ZaloFlutter.sendMessage(to: "zaloId",message: "zaloMessage",link: "zaloMessageLink");
- Post feed
ZaloPostFeed data = await ZaloFlutter.postFeed(message: "zaloContentPost",link: "zaloLinkPost");
- Send app request
ZaloSendAppRequest data = await ZaloFlutter.sendAppRequest(to: ["zaloId1, zaloId2"], message: "zaloMessage",);
Pham Tien Dung
If you have any questions, feel free to message me right away
Gmail: [email protected]
Github: https://github.com/tiendung01023
Linkedin: https://www.linkedin.com/in/tiendung01023
Facebook: https://www.facebook.com/tiendung01023