wepin_flutter 0.0.3
wepin_flutter: ^0.0.3 copied to clipboard
Flutter package of Wepin
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.3
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: Your app package name or bundle id + '.wepin'
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 : packageName + .wepin-->
<data
android:scheme="com.sample.app.wepin"
/>
</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: bundle id of your project + '.wepin'
⏩ Import SDK #
import 'package:wepin_flutter/wepin.dart';
import 'package:wepin_flutter/wepin_delegate.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');
}
});
}
}
- Add Event Listener
In order to implement a listener for handling events that occur when an error occurs in the Wepin widget or when an account is created after a successful login, you can inherit the WepinDelegate as follows.
class SampleApp extends StatefulWidget with WepinDelegate {
SampleApp({super.key});
@override
_SampleApp createState() => _SampleApp();
@override
void onWepinError(String errMsg) {
// TODO: implement onWepinError
if (kDebugMode) {
print('onWepinError : $errMsg');
}
}
@override
void onAccountSet() {
// TODO: implement onAccountSet
if (kDebugMode) {
print('onAccountSet');
}
List<Account>? accounts = _wepin.getAccounts();
if (accounts == null) {
if (kDebugMode) {
print('accounts is null');
}
return;
}
for (var account in accounts!) {
if (kDebugMode) {
print('netwrok : ${account.network}');
print('address : ${account.address}');
}
}
}
}
⏩ Methods #
Methods of Wepin SDK.
Initialize #
void initialize(BuildContext appContext, WepinOptions wepinOptions)
This method initializing Wepin SDK. If success, Wepin widget will show login page.
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.
Return value
- <bool>
trueif Wepin SDK is already initialized.
openWidget #
void openWidget()
This method shows Wepin widget.
closeWidget #
void closeWidget()
This method closes Wepin widget.
getAccounts #
List<Account>? getAccounts()
This method returns user's accounts. If user is not logged in, Wepin widget will be opened and show login page.
Return value
-
If user is logged in, it returns list of
user's accountaccount<Account>network<dynamic>address<dynamic>
-
If user is not logged in, it returns null
finalize #
void finalize()
This method finalize Wepin widget.