zalo_flutter

Creator: coderz1093

Last updated:

0 purchases

zalo_flutter Image
zalo_flutter Images
Add to Cart

Description:

zalo flutter

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!
1. Setup #
1.1 Create app Zalo #
To access Zalo APIs, you'll need to make sure to create your application.

1.2 Get ZaloAppID #
Then, you access to Dashboard (https://developers.zalo.me/app/[ZaloAppID]/settings). Remember your ZaloAppID

1.3 Import the package #
To use this plugin, follow the plugin installation instructions.
1.4 Android integration #

Open android/app/build.gradle and edit

minSdkVersion 21 // or bigger
copied to clipboard

Open to /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 -->
copied to clipboard

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>
copied to clipboard

Open file main.dart and add this widget to get HashKey

const ZaloHashKeyAndroid(),
copied to clipboard
Then, you build app 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

NOTE: If you upload file .aab to Google Store, it will generate another HashKey, copy it to Dashboard.

Add proguard for zaloSDK

-keep class com.zing.zalo.**{ *; }
-keep enum com.zing.zalo.**{ *; }
-keep interface com.zing.zalo.**{ *; }
copied to clipboard
Continue with Kotlin


Edit the file MainActivity.kt as below. Remember YourPackageName

package [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
}
}
copied to clipboard

Create file MyApplication.kt in same folder of MainActivity.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) {}
}
copied to clipboard
Continue with Java


Edit the file MainActivity.java as below. Remember YourPackageName

package [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
}
}
copied to clipboard

Create file MyApplication.java in same folder of MainActivity.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);
}
}
copied to clipboard
iOS integration #

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>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>zalosdk</string>
<string>zaloshareext</string>
</array>
<!-- ZaloFlutter end-->
</dict>
</plist>
copied to clipboard

Open 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)
}
}
copied to clipboard


Open ios/Runner.xcodeproj/project.pbxproj, search PRODUCT_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



Usage #
Add the following import to your Dart code:
import 'package:zalo_flutter/zalo_flutter.dart';
copied to clipboard
Functions:

Get HashKey Android for register app in dashboard Zalo

String? data = await ZaloFlutter.getHashKeyAndroid();
copied to clipboard

Authenticate (with app or webview)

ZaloLogin data = await ZaloFlutter.login(
refreshToken: refreshToken,
);
copied to clipboard

Log out - SDK clear oauth code in cache

await ZaloFlutter.logout();
copied to clipboard

Validate refresh token

bool data = await ZaloFlutter.validateRefreshToken(
refreshToken: refreshToken,
);
copied to clipboard

Get Zalo user profile

ZaloProfile data = await ZaloFlutter.getUserProfile(
accessToken: accessToken,
);
copied to clipboard
Author #
Pham Tien Dung
If you have any questions, feel free to message me right away

Gmail: [email protected]
Github: https://github.com/tiendung01023

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.