loyalty_flutter
A flutter plug-in for the native Loyalty library (Android and iOS).
Installation
Add dependency to your pubspec.yaml file
Add loyalty_flutter
as a dependency in your pubspec.yaml
file.
Android
Open the android project inside the android
folder of your project in Android studio
.
1. Add token to get Terra libraries
Add TekoGoogleRegistryToken to the local.properties
file (contact trung.cs@teko.vn to get
the token).
// android/local.properties
TekoGoogleRegistry.password=<your-token>
In project build.grade
(android/build.gralde
file). Add the following code:
// android/build.gradle
allprojects {
repositories {
...
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
maven {
setUrl("https://asia-southeast1-maven.pkg.dev/teko-development/teko-mobile-sdks")
authentication {
basic(BasicAuthentication)
}
credentials {
username = "_json_key_base64"
password = properties.getProperty('TekoGoogleRegistry.password')
}
}
}
}
2. Enable dataBinding and multiDex for the app module
Add some line below to the build.gradle
of app module (android/app/build.gradle
file).
//...
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
// add line below
apply plugin: 'kotlin-kapt'
//...
android {
//...
defaultConfig {
//...
multiDexEnabled true // Add this line
}
// Add 3 lines below to enable dataBinding
buildFeatures {
dataBinding true
}
//...
}
iOS
Open the ios
project insdie the android folder of your project in xcode
.
1. Setup github access token for accessing Teko iOS frameworks
Please contact Terra team to get the token
Add new environment variable to your computer with the following key: GITHUB_USER_TOKEN
.
2. Set up the Podfile
- At the beginning of your Podfile, define the source:
// on local machine
source 'https://github.com/teko-vn/Specs-ios.git'
// on CI environment
source 'https://' + ENV['GITHUB_USER_TOKEN'] + '@github.com/teko-vn/Specs-ios.git'
- Configure targets for frameworks
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
# set valid architecture
config.build_settings['VALID_ARCHS'] = 'arm64 armv7 armv7s x86_64'
# Xcode12 have to exclude arm64 for simulator architecture
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
config.build_settings["BUILD_LIBRARY_FOR_DISTRIBUTION"] = "YES"
end
end
end
Normally, in the Podfile
there is the following code:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
In this case, we update the existing code to:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
# new code
target.build_configurations.each do |config|
# set valid architecture
config.build_settings['VALID_ARCHS'] = 'arm64 armv7 armv7s x86_64'
# Xcode12 have to exclude arm64 for simulator architecture
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
config.build_settings["BUILD_LIBRARY_FOR_DISTRIBUTION"] = "YES"
end
# end of new code
end
end
Note: please do not commit <your_token_secret> to github or it will be revoked
Library usage
Get an TerraLoyalty instance
Static Method: `getInstance(String appName) → Future
Should be called in initialize phase of your app and must be called after initilizing TerraApp successful.
Get the configuration of Loyalty Service
Method: Future<Result<LoyaltyConfiguration, Exception>> getConfiguration()
Register new loyalty member
Method: Future<Result<RegisterMemberResult, Exception>> registerMember( RegisterMemeberRequest request)
Get the configuration of Loyalty Service
Method: Future<Result<LoyaltyConfiguration, Exception>> getConfiguration()
Get membership QR content
Method: Future<Result<EncryptedMemCode, Exception>> getMembershipQr()
Get the current member information
Method: Future<Result<MemberInfo, Exception>> getMemberInfo(MemberInfoRequest request)
Get all the loylaty transactions of current memeber
Method: Future<Result<TransactionHistory, Exception>> getTransactionHistory( TransactionHistoryRequest request)
Get loyalty network config
Method: Future<Result<NetworkConfigResult, Exception>> getNetworkConfig()
Get current clientID
Method: Future<Result<String, Exception>> getClientId()
Assign member card id to the member
Method: Future<Result<void, Exception>> assignMemberCardId(String memberId, String memberCardId)