A Flutter plugin that lets developers access LINE's native SDKs in Flutter apps with Dart.
The plugin helps you integrate LINE Login features in your app. You can redirect users to LINE or a web page where they log in with their LINE credentials. Example:
import 'package:flutter_line_sdk/flutter_line_sdk.dart';
void login() async {
try {
final result = await LineSDK.instance.login();
setState(() {
_userProfile = result.userProfile;
// user id -> result.userProfile.userId
// user name -> result.userProfile.displayName
// user avatar -> result.userProfile.pictureUrl
// etc...
});
} on PlatformException catch (e) {
// Error handling.
print(e);
}
}
For more examples, see the example app and API definitions.
- iOS 10.0 or later as the deployment target
- Android
minSdkVersion
set to 17 or higher (Android 4.2 or later) - LINE Login channel linked to your app
To access your LINE Login channel from a mobile platform, you need some extra configuration. In the LINE Developers console, go to your LINE Login channel settings, and enter the below information on the App settings tab.
Setting | Description |
---|---|
iOS bundle ID | Bundle identifier of your app. In Xcode, find it in your Runner project settings, on the General tab. Must be lowercase, like com.example.app . You can specify multiple bundle identifiers by typing each one on a new line. |
iOS scheme | Set to line3rdp. , followed by the bundle identifier. For example, if your bundle identifier is com.example.app , set the iOS scheme to line3rdp.com.example.app . Only one iOS scheme can be specified. |
iOS universal link | Optional. Set to the universal link configured for your app. For more information on how to handle the login process using a universal link, see Universal Links support. |
Setting | Description |
---|---|
Android package name | Required. Application's package name used to launch the Google Play store. |
Android package signature | Optional. You can set multiple signatures by typing each one on a new line. |
Android scheme | Optional. Custom URL scheme used to launch your app. |
Use the standard way of adding this package to your Flutter app, as described in the Flutter documentation. The process consists of these steps:
- Open the
pubspec.yaml
file in your app folder and, underdependencies
, addflutter_line_sdk:
. - Install it by running this in a terminal:
flutter pub get
Now, the Dart part of flutter_line_sdk
should be installed. Next, you need to set up LINE SDK for iOS and Android projects, respectively.
Open the file ios/Runner/Info.plist
in a text editor and insert this snippet just before the last </dict>
tag:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<!-- Specify URL scheme to use when returning from LINE to your app. -->
<string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<!-- Specify URL scheme to use when launching LINE from your app. -->
<string>lineauth2</string>
</array>
Because LINE SDK now requires iOS 10.0 or above and uses the iOS dynamic Framework to provide underlying native features, you must add these lines in the Runner
target in ios/Podfile
:
target 'Runner' do
+ use_frameworks!
+ platform :ios, '10.0'
No specific settings required.
Import flutter_line_sdk
to any place you want to use it in your project:
import 'package:flutter_line_sdk/flutter_line_sdk.dart';
To use the package, you need to set up your channel ID. You can do this by calling the setup
method, for example in the main
function:
- void main() => runApp(MyApp());
+ void main() {
+ WidgetsFlutterBinding.ensureInitialized();
+ LineSDK.instance.setup("${your_channel_id}").then((_) {
+ print("LineSDK Prepared");
+ });
+ runApp(App());
+ }
This is merely an example. You can call setup
any time you want, provided you call it exactly once, before calling any other LINE SDK methods.
To help you get started with this package, we list several basic usage examples below. All available flutter_line_sdk
methods are documented on the Dart Packages site.
Now you are ready to let your user log in with LINE.
Get the login result by assigning the value of Future<LoginResult>
to a variable.
To handle errors gracefully, wrap the invocation in a try...on
statement:
void _signIn() async {
try {
final result = await LineSDK.instance.login();
// user id -> result.userProfile.userId
// user name -> result.userProfile.displayName
// user avatar -> result.userProfile.pictureUrl
} on PlatformException catch (e) {
_showDialog(context, e.toString());
}
}
By default, login
will use ["profile"]
as its scope. If you need other scopes, pass them in a list to login
. See the Scopes documentation for more.
final result = await LineSDK.instance.login(
scopes: ["profile", "openid", "email"]);
try {
await LineSDK.instance.logout();
} on PlatformException catch (e) {
print(e.message);
}
try {
final result = await LineSDK.instance.getProfile();
// user id -> result.userId
// user name -> result.displayName
// user avatar -> result.pictureUrl
} on PlatformException catch (e) {
print(e.message);
}
try {
final result = await LineSDK.instance.currentAccessToken;
// acceess token -> result.value
} on PlatformException catch (e) {
print(e.message);
}
try {
final result = await LineSDK.instance.verifyAccessToken();
// result.data is accessible if the token is valid.
} on PlatformException catch (e) {
print(e.message);
// token is not valid, or any other error.
}
try {
final result = await LineSDK.instance.refreshToken();
// acceess token -> result.value
// expires duration -> result.expiresIn
} on PlatformException catch (e) {
print(e.message);
}
Normally, you don't need to refresh access tokens manually, because any API call in LINE SDK will try to refresh the access token automatically when necessary. We do not recommend refreshing access tokens yourself. It's generally easier, more secure, and more future-proof to let the LINE SDK manage access tokens automatically.
All APIs can throw a PlatformException
with error code
and a message
. Use this information to identify when an error happens inside the native SDK.
Error codes and messages will vary between iOS and Android. Be sure to read the error definition on iOS and Android to provide better error recovery and user experience on different platforms.
If you believe you found a vulnerability or you have an issue related to security, please DO NOT open a public issue. Instead, email us at [email protected].
Before contributing to this project, please read CONTRIBUTING.md.