diff --git a/lib/Iamport_certification.dart b/lib/iamport_certification.dart similarity index 72% rename from lib/Iamport_certification.dart rename to lib/iamport_certification.dart index 44894bf..031cb83 100644 --- a/lib/Iamport_certification.dart +++ b/lib/iamport_certification.dart @@ -13,16 +13,9 @@ import 'package:iamport_flutter/widget/iamport_webview.dart'; import 'package:iamport_webview_flutter/iamport_webview_flutter.dart'; class IamportCertification extends StatelessWidget { - final PreferredSizeWidget? appBar; - final Widget? initialChild; - final String userCode; - final CertificationData data; - final callback; - final Set>? gestureRecognizers; - final String? customUserAgent; - IamportCertification({ - Key? key, + const IamportCertification({ + super.key, this.appBar, this.initialChild, required this.userCode, @@ -30,28 +23,35 @@ class IamportCertification extends StatelessWidget { required this.callback, this.gestureRecognizers, this.customUserAgent, - }) : super(key: key); + }); + final PreferredSizeWidget? appBar; + final Widget? initialChild; + final String userCode; + final CertificationData data; + final ValueSetter> callback; + final Set>? gestureRecognizers; + final String? customUserAgent; @override Widget build(BuildContext context) { var redirectUrl = UrlData.redirectUrl; - if (this.data.mRedirectUrl != null && this.data.mRedirectUrl!.isNotEmpty) { - redirectUrl = this.data.mRedirectUrl!; + if (data.mRedirectUrl != null && data.mRedirectUrl!.isNotEmpty) { + redirectUrl = data.mRedirectUrl!; } - IamportValidation validation = + final validation = IamportValidation.fromCertificationData(userCode, data, callback); if (validation.getIsValid()) { return IamportWebView( type: ActionType.auth, - appBar: this.appBar, - initialChild: this.initialChild, - gestureRecognizers: this.gestureRecognizers, - customUserAgent: this.customUserAgent, - executeJS: (WebViewController controller) { - controller.evaluateJavascript(''' - IMP.init("${this.userCode}"); - IMP.certification(${jsonEncode(this.data.toJson())}, function(response) { + appBar: appBar, + initialChild: initialChild, + gestureRecognizers: gestureRecognizers, + customUserAgent: customUserAgent, + executeJS: (WebViewController controller) async { + await controller.evaluateJavascript(''' + IMP.init("$userCode"); + IMP.certification(${jsonEncode(data.toJson())}, function(response) { const query = []; Object.keys(response).forEach(function(key) { query.push(key + "=" + response[key]); @@ -60,9 +60,7 @@ class IamportCertification extends StatelessWidget { }); '''); }, - useQueryData: (Map data) { - this.callback(data); - }, + useQueryData: callback, isPaymentOver: (String url) { return url.startsWith(redirectUrl); },