@@ -22,57 +22,43 @@ class FlutterLineSdkPlugin : MethodCallHandler, FlutterPlugin, ActivityAware {
22
22
override fun onMethodCall (call : MethodCall , result : Result ) {
23
23
when (call.method) {
24
24
" 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()
29
29
lineSdkWrapper.setupBetaConfig(
30
- channelId,
31
- openDiscoveryIdDocumentUrl,
32
- apiServerBaseUrl,
33
- webLoginPageUrl
30
+ channelId,
31
+ openDiscoveryIdDocumentUrl,
32
+ apiServerBaseUrl,
33
+ webLoginPageUrl
34
34
)
35
35
result.success(null )
36
36
}
37
37
" 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 )
47
42
}
48
- lineSdkWrapper.setupSdk(activity, channelId)
49
- result.success(null )
50
43
}
51
44
" 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(
68
53
loginRequestCode,
69
54
activity,
70
55
scopes = scopes,
71
56
onlyWebLogin = isWebLogin,
72
57
botPromptString = botPrompt,
73
58
idTokenNonce = idTokenNonce,
74
59
result = result
75
- )
60
+ )
61
+ }
76
62
}
77
63
" getProfile" -> lineSdkWrapper.getProfile(result)
78
64
" currentAccessToken" -> lineSdkWrapper.getCurrentAccessToken(result)
@@ -84,12 +70,26 @@ class FlutterLineSdkPlugin : MethodCallHandler, FlutterPlugin, ActivityAware {
84
70
}
85
71
}
86
72
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
+
87
86
override fun onAttachedToEngine (binding : FlutterPlugin .FlutterPluginBinding ) {
88
87
onAttachedToEngine(binding.binaryMessenger)
89
88
}
90
89
91
90
override fun onDetachedFromEngine (binding : FlutterPlugin .FlutterPluginBinding ) {
92
- methodChannel = null ;
91
+ methodChannel?.setMethodCallHandler(null )
92
+ methodChannel = null
93
93
}
94
94
95
95
override fun onAttachedToActivity (binding : ActivityPluginBinding ) {
@@ -122,7 +122,7 @@ class FlutterLineSdkPlugin : MethodCallHandler, FlutterPlugin, ActivityAware {
122
122
123
123
private fun onAttachedToEngine (messenger : BinaryMessenger ) {
124
124
methodChannel = MethodChannel (messenger, CHANNEL_NAME )
125
- methodChannel!! .setMethodCallHandler(this )
125
+ methodChannel? .setMethodCallHandler(this )
126
126
}
127
127
128
128
companion object {
0 commit comments