@@ -22,57 +22,43 @@ class FlutterLineSdkPlugin : MethodCallHandler, FlutterPlugin, ActivityAware {
2222 override fun onMethodCall (call : MethodCall , result : Result ) {
2323 when (call.method) {
2424 " toBeta" -> run {
25- val channelId: String = call.argument(" channelId" ) ? : " "
26- val openDiscoveryIdDocumentUrl: String = call.argument(" openDiscoveryIdDocumentUrl" ) ? : " "
27- val apiServerBaseUrl: String = call.argument(" apiServerBaseUrl" ) ? : " "
28- val webLoginPageUrl: String = call.argument(" webLoginPageUrl" ) ? : " "
25+ val channelId = call.argument< String > (" channelId" ).orEmpty()
26+ val openDiscoveryIdDocumentUrl = call.argument< String > (" openDiscoveryIdDocumentUrl" ).orEmpty()
27+ val apiServerBaseUrl = call.argument< String > (" apiServerBaseUrl" ).orEmpty()
28+ val webLoginPageUrl = call.argument< String > (" webLoginPageUrl" ).orEmpty()
2929 lineSdkWrapper.setupBetaConfig(
30- channelId,
31- openDiscoveryIdDocumentUrl,
32- apiServerBaseUrl,
33- webLoginPageUrl
30+ channelId,
31+ openDiscoveryIdDocumentUrl,
32+ apiServerBaseUrl,
33+ webLoginPageUrl
3434 )
3535 result.success(null )
3636 }
3737 " setup" -> {
38- val channelId: String = call.argument<String ?>(" channelId" ).orEmpty()
39- val activity = activity
40- if (activity == null ) {
41- result.error(
42- " no_activity_found" ,
43- " There is no valid Activity found to present LINE SDK Login screen." ,
44- null
45- )
46- return
38+ withActivity(result) { activity ->
39+ val channelId = call.argument<String >(" channelId" ).orEmpty()
40+ lineSdkWrapper.setupSdk(activity, channelId)
41+ result.success(null )
4742 }
48- lineSdkWrapper.setupSdk(activity, channelId)
49- result.success(null )
5043 }
5144 " login" -> {
52- val activity = this .activity
53- if (activity == null ) {
54- result.error(
55- " no_activity_found" ,
56- " There is no valid Activity found to present LINE SDK Login screen." ,
57- null
58- )
59- return
60- }
61-
62- val scopes = call.argument(" scopes" ) ? : emptyList<String >()
63- val isWebLogin = call.argument(" onlyWebLogin" ) ? : false
64- val botPrompt = call.argument(" botPrompt" ) ? : " normal"
65- val idTokenNonce: String? = call.argument(" idTokenNonce" )
66- val loginRequestCode = call.argument<Int ?>(" loginRequestCode" ) ? : DEFAULT_ACTIVITY_RESULT_REQUEST_CODE
67- lineSdkWrapper.login(
45+ withActivity(result) { activity ->
46+ val scopes = call.argument<List <String >>(" scopes" ).orEmpty()
47+ val isWebLogin = call.argument<Boolean >(" onlyWebLogin" ) ? : false
48+ val botPrompt = call.argument<String >(" botPrompt" ) ? : " normal"
49+ val idTokenNonce = call.argument<String >(" idTokenNonce" )
50+ val loginRequestCode = call.argument<Int >(" loginRequestCode" )
51+ ? : DEFAULT_ACTIVITY_RESULT_REQUEST_CODE
52+ lineSdkWrapper.login(
6853 loginRequestCode,
6954 activity,
7055 scopes = scopes,
7156 onlyWebLogin = isWebLogin,
7257 botPromptString = botPrompt,
7358 idTokenNonce = idTokenNonce,
7459 result = result
75- )
60+ )
61+ }
7662 }
7763 " getProfile" -> lineSdkWrapper.getProfile(result)
7864 " currentAccessToken" -> lineSdkWrapper.getCurrentAccessToken(result)
@@ -84,12 +70,26 @@ class FlutterLineSdkPlugin : MethodCallHandler, FlutterPlugin, ActivityAware {
8470 }
8571 }
8672
73+ private fun withActivity (result : Result , block : (Activity ) -> Unit ) {
74+ val activity = this .activity
75+ if (activity == null ) {
76+ result.error(
77+ " no_activity_found" ,
78+ " There is no valid Activity found to present LINE SDK Login screen." ,
79+ null
80+ )
81+ return
82+ }
83+ block(activity)
84+ }
85+
8786 override fun onAttachedToEngine (binding : FlutterPlugin .FlutterPluginBinding ) {
8887 onAttachedToEngine(binding.binaryMessenger)
8988 }
9089
9190 override fun onDetachedFromEngine (binding : FlutterPlugin .FlutterPluginBinding ) {
92- methodChannel = null ;
91+ methodChannel?.setMethodCallHandler(null )
92+ methodChannel = null
9393 }
9494
9595 override fun onAttachedToActivity (binding : ActivityPluginBinding ) {
@@ -122,7 +122,7 @@ class FlutterLineSdkPlugin : MethodCallHandler, FlutterPlugin, ActivityAware {
122122
123123 private fun onAttachedToEngine (messenger : BinaryMessenger ) {
124124 methodChannel = MethodChannel (messenger, CHANNEL_NAME )
125- methodChannel!! .setMethodCallHandler(this )
125+ methodChannel? .setMethodCallHandler(this )
126126 }
127127
128128 companion object {
0 commit comments