22
22
/// {@template error_handling}
23
23
/// This method redirects calls to the LINE SDK for the relevant native platform (iOS or Android).
24
24
/// If an error happens in the native platform, a [PlatformException] is thrown. See
25
- /// [PlatformException.code] and [PlatformException.message] for error details.
25
+ /// [PlatformException.code] and [PlatformException.message] for error details.
26
26
///
27
27
/// The LINE SDK implementation differs between iOS and Android, which means error codes and messages
28
28
/// can also be different. For platform-specific error information, see
35
35
part of flutter_line_sdk;
36
36
37
37
/// A general manager class for LINE SDK login features.
38
- ///
39
- /// Don't create your own instance of this class. Instead, call [LineSDK.instance] to get a shared
38
+ ///
39
+ /// Don't create your own instance of this class. Instead, call [LineSDK.instance] to get a shared
40
40
/// singleton on which you can call other methods.
41
41
class LineSDK {
42
-
43
42
/// The method channel connected to the native side of the LINE SDK.
44
- ///
43
+ ///
45
44
/// Don't use this channel directly. Instead, call the public methods on the [LineSDK] class.
46
45
static const MethodChannel channel =
47
46
const MethodChannel ('com.linecorp/flutter_line_sdk' );
48
-
47
+
49
48
/// The shared singleton object of `LineSDK` .
50
- ///
51
- /// Always use this instance (rather than a self-created instance) to interact with the login
49
+ ///
50
+ /// Always use this instance (rather than a self-created instance) to interact with the login
52
51
/// process of the LINE SDK.
53
52
static final LineSDK instance = LineSDK ._();
54
53
55
54
LineSDK ._();
56
55
57
56
/// Sets up the SDK with a [channelId] and optional [universalLink] .
58
- ///
57
+ ///
59
58
/// This method should be called once and only once, before any other methods in [LineSDK] .
60
- /// Find your [channelId] in the [LINE Developers Console] (https://developers.line.biz/console).
61
- ///
62
- /// If you need to navigate from LINE back to your app via a universal link, you must also:
59
+ /// Find your [channelId] in the [LINE Developers Console] (https://developers.line.biz/console).
60
+ ///
61
+ /// If you need to navigate from LINE back to your app via a universal link, you must also:
63
62
/// 1. Specify the link URL in the LINE Developers Console
64
63
/// 2. Prepare your server and domain to handle the URL
65
- /// 3. Pass the URL in [universalLink] .
66
- ///
67
- /// For more about this, see the section "Universal Links support" in
68
- /// [Setting up your project] (https://developers.line.biz/en/docs/ios-sdk/swift/setting-up-project/).
69
- /// If you don't pass a [universalLink] in this method, LINE SDK will use the traditional URL
64
+ /// 3. Pass the URL in [universalLink] .
65
+ ///
66
+ /// For more about this, see the section "Universal Links support" in
67
+ /// [Setting up your project] (https://developers.line.biz/en/docs/ios-sdk/swift/setting-up-project/).
68
+ /// If you don't pass a [universalLink] in this method, LINE SDK will use the traditional URL
70
69
/// scheme to open your app when logging in through LINE.
71
70
Future <void > setup (String channelId, {String universalLink}) async {
72
- await channel.invokeMethod (
73
- 'setup' ,
74
- < String , String > {
75
- 'channelId' : channelId,
76
- 'universalLink' : universalLink
77
- }
78
- );
71
+ await channel.invokeMethod ('setup' , < String , String > {
72
+ 'channelId' : channelId,
73
+ 'universalLink' : universalLink
74
+ });
79
75
}
80
76
81
- /// Logs the user into LINE with the specified [scopes] and [option] , by either opening the
82
- /// LINE client for an existing logged in user, or a web view if the LINE client isn't installed
77
+ /// Logs the user into LINE with the specified [scopes] and [option] , by either opening the
78
+ /// LINE client for an existing logged in user, or a web view if the LINE client isn't installed
83
79
/// on the user's device.
84
- ///
85
- /// By default, the login process uses only `"profile"` as its required scope. If you need
86
- /// more scopes, put the ones you want (in addition to the default `"profile"` ) in [scopes] as a
87
- /// list.
88
- ///
89
- /// If [scopes] contains `"profile"` , the user profile is returned in the result as
80
+ ///
81
+ /// By default, the login process uses only `"profile"` as its required scope. If you need
82
+ /// more scopes, put the ones you want (in addition to the default `"profile"` ) in [scopes] as a
83
+ /// list.
84
+ ///
85
+ /// If [scopes] contains `"profile"` , the user profile is returned in the result as
90
86
/// [LoginResult.userProfile] . If `"profile"` is not included, the value of [LoginResult.userProfile]
91
- /// will be null.
92
- ///
93
- /// An access token is issued if the user authorizes your app. This token, along with a refresh
94
- /// token, is automatically stored in a secure place in your app for later use. You don't need to
95
- /// refresh the access token manually. Any following API calls will try to refresh the access
87
+ /// will be null.
88
+ ///
89
+ /// An access token is issued if the user authorizes your app. This token, along with a refresh
90
+ /// token, is automatically stored in a secure place in your app for later use. You don't need to
91
+ /// refresh the access token manually. Any following API calls will try to refresh the access
96
92
/// token when necessary. However, you can refresh the access token manually with [refreshToken()] .
97
- ///
98
- /// You can control some other login behaviors, like whether to use a web page for login, or how
99
- /// to ask the user to add your bot as a friend. To do so, create a [LoginOption] object and pass
93
+ ///
94
+ /// You can control some other login behaviors, like whether to use a web page for login, or how
95
+ /// to ask the user to add your bot as a friend. To do so, create a [LoginOption] object and pass
100
96
/// it to the [option] parameter.
101
- ///
97
+ ///
102
98
/// {@macro error_handling}
103
99
Future <LoginResult > login (
104
- { List <String > scopes = const ["profile" ],
105
- LoginOption option
106
- }) async
107
- {
108
- String result = await channel.invokeMethod (
109
- 'login' ,
110
- < String , dynamic > {
111
- 'scopes' : scopes,
112
- 'onlyWebLogin' : option? .onlyWebLogin,
113
- 'botPrompt' : option? .botPrompt
114
- }
115
- );
100
+ {List <String > scopes = const ["profile" ], LoginOption option}) async {
101
+ String result = await channel.invokeMethod ('login' , < String , dynamic > {
102
+ 'scopes' : scopes,
103
+ 'onlyWebLogin' : option? .onlyWebLogin,
104
+ 'botPrompt' : option? .botPrompt
105
+ });
116
106
if (result == null ) return null ;
117
107
return LoginResult ._(json.decode (result));
118
108
}
119
109
120
110
/// Logs out the current user by revoking the related tokens.
121
- ///
111
+ ///
122
112
/// {@macro error_handling}
123
113
Future <void > logout () async {
124
114
await channel.invokeMethod ('logout' );
125
115
}
126
116
127
117
/// Gets the current access token in use.
128
- ///
129
- /// This returns a `Future<StoredAccessToken>` , with the access token value contained in the
130
- /// result [StoredAccessToken.value] . If the user isn't logged in, it returns a `null` value as
131
- /// the [Future] result.
132
- ///
133
- /// A valid [StoredAccessToken] object doesn't necessarily mean the access token itself is valid.
118
+ ///
119
+ /// This returns a `Future<StoredAccessToken>` , with the access token value contained in the
120
+ /// result [StoredAccessToken.value] . If the user isn't logged in, it returns a `null` value as
121
+ /// the [Future] result.
122
+ ///
123
+ /// A valid [StoredAccessToken] object doesn't necessarily mean the access token itself is valid.
134
124
/// It may have expired or been revoked by the user from another device or LINE client.
135
- ///
125
+ ///
136
126
/// {@macro error_handling}
137
127
Future <StoredAccessToken > get currentAccessToken async {
138
128
String result = await channel.invokeMethod ('currentAccessToken' );
@@ -141,9 +131,9 @@ class LineSDK {
141
131
}
142
132
143
133
/// Gets the user’s profile.
144
- ///
134
+ ///
145
135
/// Using this method requires the `"profile"` scope.
146
- ///
136
+ ///
147
137
/// {@macro error_handling}
148
138
Future <UserProfile > getProfile () async {
149
139
String result = await channel.invokeMethod ('getProfile' );
@@ -152,14 +142,14 @@ class LineSDK {
152
142
}
153
143
154
144
/// Refreshes the access token.
155
- ///
145
+ ///
156
146
/// If the token refresh process finishes successfully, the refreshed access token will be
157
147
/// automatically stored in the user's device. You can wait for the result of this method or get
158
- /// the refreshed token with [currentAccessToken] .
159
- ///
160
- /// You don't need to refresh the access token manually. Any API call will attempt to refresh the
148
+ /// the refreshed token with [currentAccessToken] .
149
+ ///
150
+ /// You don't need to refresh the access token manually. Any API call will attempt to refresh the
161
151
/// access token when necessary.
162
- ///
152
+ ///
163
153
/// {@macro error_handling}
164
154
Future <AccessToken > refreshToken () async {
165
155
String result = await channel.invokeMethod ('refreshToken' );
@@ -168,19 +158,19 @@ class LineSDK {
168
158
}
169
159
170
160
/// Checks whether the stored access token is valid against the LINE authentication server.
171
- ///
161
+ ///
172
162
/// {@macro error_handling}
173
163
Future <AccessTokenVerifyResult > verifyAccessToken () async {
174
164
String result = await channel.invokeMethod ('verifyAccessToken' );
175
165
if (result == null ) return null ;
176
166
return AccessTokenVerifyResult ._(json.decode (result));
177
167
}
178
168
179
- /// Gets the friendship status between the user and the official account linked to your LINE Login
169
+ /// Gets the friendship status between the user and the official account linked to your LINE Login
180
170
/// channel.
181
- ///
171
+ ///
182
172
/// Using this method requires the `"profile"` scope.
183
- ///
173
+ ///
184
174
/// {@macro error_handling}
185
175
Future <BotFriendshipStatus > getBotFriendshipStatus () async {
186
176
String result = await channel.invokeMethod ('getBotFriendshipStatus' );
0 commit comments