2.1 open ${your flutter project} /android/app/build.gradle
2.1.1 add project config and update the minSdkVersion to 23
//Modify these configurations
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.particle_auth_test"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
//After modification:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.particle_auth_test"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 23 // required by particle sdk
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
//get from https://dashboard.particle.network/
manifestPlaceholders["PN_PROJECT_ID"] = "772f7499-1d2e-40f4-8e2c-7b6dd47db9de" //your project id
manifestPlaceholders["PN_PROJECT_CLIENT_KEY"] = "ctWeIc2UBA6sYTKJknT9cu9LBikF00fbk1vmQjsV" //your project client key
manifestPlaceholders["PN_APP_ID"] = "01a23ce8-d2e9-4b37-9eab-bf477279e53e" //your app id
}
2.1.2 update Java Version to 11 and add dataBinding config
3.4 Replace YOUR_PROJECT_UUID, YOUR_PROJECT_CLIENT_KEY, and YOUR_PROJECT_APP_UUID with the new values created in your Dashboard
3.5 Edit Podfile, you should follow Podfile required to edit Podfile.
3.6 More important to note, our SDK is static XCFramework, when introduced, you must specify the use of static libraries, use_frameworks! :linkage => :static
target 'Runner' do
use_frameworks! :linkage => :static
...other
end
Initialize the SDK
Before using the SDK, you have to call init(Required)
// Get your project id and client key from dashboard, https://dashboard.particle.networkconst projectId ="";const clientK =""; if (projectId.isEmpty || clientK.isEmpty) {throwconstFormatException( 'You need set project info, get your project id and client key from dashboard, https://dashboard.particle.network');
}ParticleInfo.set(projectId, clientK);ParticleAuth.init(currChainInfo, env);ParticleAuthCore.init();
Connect
If loginType is email or phone, you can pass email address or phone number to account.
If loginType is JWT, you must pass JWT token to account.
SocialLoginPrompt: optional, only google, discord and microsoft support it.
If loginType is email or phone, below parameter is optional, other wise, they are useless.
The supportAuthTypes controls which types of social login buttons are displayed at the bottom of the login page.
The loginPageConfig controls the title, description, and image displayed on the login page.
final userInfo =awaitParticleAuthCore.connect(loginType, account: account, supportAuthTypes: supportAuthTypes, loginPageConfig:LoginPageConfig( imagePath:"your icon url", // icon url or base64 string projectName:"Flutter Example", description:"Welcome to login", imageType:"url")); // url | base64
final userInfo =awaitParticleAuthCore.connect(LoginType.google);
Is Connected
final isConnected =awaitParticleAuthCore.isConnected();
Disconnect
final result =awaitParticleAuthCore.disconnect();
Get user info
final userInfo =awaitParticleAuthCore.getUserInfo();
Get EVM address
final address =awaitEvm.getAddress();
EVM Sign message and sign message unique
In EVM chain requires a hexadecimal string
If your message is already a hexadecimal string, don't need to convert again, if your message is a human readable string, like "Hello Particle!", you should convert it to hexadecimal string.
final messageHex ="0x${StringUtils.toHexString("Hello Particle!")}";String signature =awaitEvm.personalSign(messageHex);String signature =awaitEvm.personalSignUnique(messageHex);
EVM Sign typed data and sign typed data unique
If your typed data is already a hexadecimal string, don't need to convert again, if your typed data is a human readable string, is a json string, you should convert it to hexadecimal string.
// set security account config, // the first parameter is promptSettingWhenSign, default value is 1.// the second parameter is promptMasterPasswordSettingWhenLogin, default value is 0.// 0 no prompt// 1 first time show prompt// 2 every time show promptfinal config =SecurityAccountConfig(1, 2);ParticleAuth.setSecurityAccountConfig(config);
Open account and security page
If user is expired, should return error, If user is expired, should return error, otherwise return nothing.
try {String result =awaitParticleAuthCore.openAccountAndSecurity();print("openAccountAndSecurity: $result");} catch (error) {print("openAccountAndSecurity: $error");showToast("openAccountAndSecurity: $error");}
Blind sign enable
This switch will work if the following conditions are met:
1. your account is connected with JWT
2. your account does not set payment password
3. SecurityAccountConfig.promptSettingWhenSign is 0, you can call ParticleAuth.setSecurityAccountConfig to update its value.
staticvoidsetBlindEnable(bool enable) async {ParticleAuthCore.setBlindEnable(enable);}staticvoidgetBlindEnable() async {final result =ParticleAuthCore.getBlindEnable();print("getBlindEnable: $result");showToast("getBlindEnable: $result");}