초기화하기
Wepin widget flutter SDK를 초기화하는 방법입니다.
초기화하기
먼저 위핀 인스턴스를 생성하고 앱 위젯의 BuildContext와 앱 등록 후 할당 받은 앱 ID와 앱 키로 위핀 위젯을 초기화 합니다.
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';
final String _appId = "app_id_eg12sf3491azgs520";
final String _appKey = "ak_test_ghq1D5s1sfG234sbnhdsw24mnovk313";
late Wepin _wepin;
@override
void initState() {
super.initState();
_wepin = Wepin();
_handleDeepLink() // 딥링크 처리함수
}
@override
Widget build(BuildContext context) {
print('SampleApp_build');
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Wepin Flutter Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () => _initialize(context),
child: const Text('initialize')),
],
),
),
),
);
}
void _initialize(BuildContext context) {
WidgetAttributes widgetAttributes = WidgetAttributes('ko', 'krw');
WepinOptions wepinOptions =
WepinOptions(_appId, _appSdkKey, widgetAttributes);
_wepin.initialize(context, wepinOptions);
}
WepinOptions
초기화에 사용되는 파라미터 WepinOptions
클래스의 인터페이스는 아래와 같습니다.
public class WepinOptions {
final String _appId; // 앱 아이디
final String _appKey; // 앱 키
final WidgetAttributes _widgetAttributes; // 위젯 속성
}
public class WidgetAttributes {
final String _defaultLanguage;
final String _defaultCurrency;
}
appId: String 앱 등록시 할당 받은 ID
appKey: String 앱 등록시 할당 받은 키 값
attributes: Object (optional) 위핀 위젯의 속성 값
defaultLanguage: String 위젯 기본 언어 설정, 기본 값은
ko
입니다. 현재 지원하는 언어는en
,ko
이렇게 2가지 입니다.defaultCurrency: String 위젯 기본 통화 설정, 기본 값은
KRW
입니다. 현재 지원하는 통화는USD
,KRW
이렇게 2가지 입니다.
isInitialized
isInitialized
메서드를 이용해서 Wepin이 정상적으로 초기화 되었는지 확인할 수 있습니다.
반환값은 아래와 같습니다.
bool init 결괏값, init이 정상적으로 잘 된 경우
true
실패한 경우false
를 반환합니다.
if(_wepin.isInitialized()) {
// Success to initialize wepin
}
DeepLink / Universal Link 처리하기
앱의 Info 파일 또는 AndroidManifest에 추가한 URL schemes 을 처리하기 위해 위핀을 사용하는 앱에 아래와 같이 처리하는 코드를 추가합니다.
import 'package:uni_links/uni_links.dart';
StreamSubscription? _sub;
// Handle incoming links - the ones that the app will recieve from the OS
// while already started.
void _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;
print('got_uri: $uri');
_wepin.handleWepinLink(uri!);
}, onError: (Object err) {
if (!mounted) return;
print('got_err: $err');
});
}
}
Last updated
Was this helpful?