wepin-flutter-sdk
Wepin Flutter SDK for Android OS and iOS
⏩ Get App ID and Key
Contact to wepin.contact@iotrust.kr
⏩ Install
wepin-flutter-sdk
Add a dependency 'wepin_flutter' in your pubspec.yaml file.
dependencies:
wepin_flutter: ^0.0.4
or
flutter pub add wepin_flutter
⏩ Add Permission for Android
Add the below line in your app's AndroidMainfest.xml
file
<uses-permission android:name="android.permission.INTERNET" />
⏩ Config Deep Link
Deep link scheme format: 'wepin.' + Your App ID
For Android
Add the below line in your app's AndroidMainfest.xml
file
<activity
android:name=".MainActivity"
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" />
<!--For Deep Link => Urlscheme Format : wepin. + appID-->
<data
android:scheme="wepin.88889999000000000000000000000000"
/>
</intent-filter>
</activity>
For iOS
Add the URL scheme as below:
- Open your iOS project with the xcode
- Click on Project Navigator
- Select Target Project in Targets
- Select Info Tab
- Click the '+' buttons on URL Types
- Enter Identifier and URL Schemes
- Idenetifier: bundle id of your project
- URL Schems: 'wepin.' + Your App ID
⏩ Import SDK
import 'package:wepin_flutter/wepin.dart';
import 'package:wepin_flutter/wepin_inputs.dart';
import 'package:wepin_flutter/wepin_outputs.dart';
⏩ Initialize
- Create Wepin instance
Wepin _wepin = Wepin();
- Add method in your app's 'initState()' for Handing Deeplink
import 'package:uni_links/uni_links.dart';
....
class _SampleApp extends State<SampleApp> {
StreamSubscription? _sub;
final String _appId = 'test_app_id';
final String _appSdkKey =
'test_app_key';
@override
void initState() {
if (kDebugMode) {
print('initState');
}
super.initState();
_wepin = Wepin();
_handleDeepLink();
}
....
// Handle incoming links - the ones that the app will recieve from the OS
// while already started.
void _handleDeepLink() {
if (kDebugMode) {
print('_handleDeepLink');
}
if (!kIsWeb) {
// It will handle app links while the app is already started - be it in
// the foreground or in the background.
_sub = uriLinkStream.listen((Uri? uri) {
if (!mounted) return;
if (kDebugMode) {
print('got_uri: $uri');
}
_wepin.handleWepinLink(uri!);
}, onError: (Object err) {
if (!mounted) return;
if (kDebugMode) {
print('got_err: $err');
}
});
}
}
⏩ Methods
Methods of Wepin SDK.
Initialize
Future<void> initialize(BuildContext appContext, WepinOptions wepinOptions)
This method initializing Wepin SDK.
Parameters
appContext
<BuildContext> : context of your appwepinOptions
<WepinOptions>appId
<String>appKey
<String>widgetAttributes
<WidgetAttributes>- defaultLanguage
- defaultCurrency
Example
WidgetAttributes widgetAttributes = WidgetAttributes('ko', 'krw');
WepinOptions wepinOptions =
WepinOptions(_appId, _appSdkKey, widgetAttributes);
_wepin.initialize(context, wepinOptions)
isInitialized
bool isInitialized()
This method checks Wepin SDK is initialized.
Example
_wepin.isInitialized()
Return value
- <bool>
true
if Wepin SDK is already initialized.
openWidget
void openWidget()
This method shows Wepin widget
Example
_wepin.openWidget()
closeWidget
void closeWidget()
This method closes Wepin widget.
Example
_wepin.closeWidget()
getAccounts
List<Account>? getAccounts()
This method returns user's accounts.
Example
_wepin.getAccounts()
Return value
-
If user is logged in, it returns list of
user's account
account
<Account>network
<dynamic>address
<dynamic>
-
If user is not logged in, it returns null
finalize
void finalize()
This method finalize Wepin widget.
Example
_wepin.finalize()
getStatus (Support from version 0.0.4-alpha)
Future<String> getStatus()
The method returns lifecycle of wepin.
Example
await _wepin.getStatus()
Return value
- WepinLifeCycle
not_initialized
: if wepin is not initializedinitializing
: if wepin is initializinginitialized
: if wepin is initializedbefore_login
: if wepin is initialized but the user is not logged inlogin
: if the user is logged in
login (Support from version 0.0.4-alpha)
Future<WepinUser> login()
This method returns information of the logged-in user. If a user is not logged in, Wepin widget will show login page.
Example
await _wepin.login()
Return value
- WepinUser
status
<String> <'success'|'fail'>UserInfo?
userId
<dynamic>email
<dynamic>provider
<dynamic> <'google'|'apple'|'email'|'naver'|'discord'|'external_token'>
getSignForLogin (Support from version 0.0.4-alpha)
This method signs the idToken received after logging in with OAuth using a PrivateKey.
String getSignForLogin(String privKey, String idToken)
Example
_wepin.getSignForLogin(_testPrivKey, _testIdToken);
Parameters
privKey
idToken
Return value
- signned token
Please inquire about the issuance of a private key by contacting wepin.contact@iotrust.kr
loginWithExternalToken (Support from version 0.0.4-alpha)
This method logs in to the Wepin with external token(e.g., idToken).
Future<WepinUser> loginWithExternalToken(String idToken, String sign)
Example
await _wepin.loginWithExternalToken(_testIdToken, _testSignedIdToken)
Parameters
idToken
sign
Return value
- WepinUser
status
<String> <'success'|'fail'>UserInfo?
userId
<dynamic>email
<dynamic>provider
<dynamic> <'google'|'apple'|'email'|'naver'|'discord'|'external_token'>
logout (Support from version 0.0.4-alpha)
This method logs out from the Wepin
Future<void> logout()
Example
await _wepin.logout()