flutter_line_sdk 1.2.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 93

flutter_line_sdk #

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.

For more examples, see the example app and API definitions.

Prerequisites #

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.

iOS app settings #

iOS bundle IDBundle 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 schemeSet 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 linkOptional. 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.

Android app settings #

Android package nameRequired. Application's package name used to launch the Google Play store.
Android package signatureOptional. You can set multiple signatures by typing each one on a new line.
Android schemeOptional. Custom URL scheme used to launch your app.

Installation #

Adding flutter_line_sdk package #

Use the standard way of adding this package to your Flutter app, as described in the Flutter documentation. The process consists of these steps:

  1. Open the pubspec.yaml file in your app folder and, under dependencies, add flutter_line_sdk:.
  2. 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.

Set up LINE SDK #

iOS #

Open the file ios/Runner/Info.plist in a text editor and insert this snippet just before the last </dict> tag:

      <!-- Specify URL scheme to use when returning from LINE to your app. -->
  <!-- Specify URL scheme to use when launching LINE from your app. -->

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'

Android #

No specific settings required.

Importing and using #

Setup #

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.

Login #

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"]);

Logout #

try {
  await LineSDK.instance.logout();
} on PlatformException catch (e) {

Get user profile #

try {
  final result = await LineSDK.instance.getProfile();
  // user id -> result.userId
  // user name -> result.displayName
  // user avatar -> result.pictureUrl
} on PlatformException catch (e) {

Get current stored access token #

try {
  final result = await LineSDK.instance.currentAccessToken;
  // acceess token -> result.value
} on PlatformException catch (e) {

Verify access token with LINE server #

try {
  final result = await LineSDK.instance.verifyAccessToken();
  // result.data is accessible if the token is valid.
} on PlatformException catch (e) {
  // token is not valid, or any other error.

Refresh current access token #

try {
  final result = await LineSDK.instance.refreshToken();
  // acceess token -> result.value
  // expires duration -> result.expiresIn
} on PlatformException catch (e) {

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.

Error handling #

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.

Contributing #

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 dl_oss_dev@linecorp.com.

Before contributing to this project, please read CONTRIBUTING.md.

1.2.6 #

Fixed #

  • Hot restarting will no longer cause a connection lost on iOS simulator and device. #17

1.2.5 #

Fixed #

  • Remove version specified annotation. Now Android SDK can be built without problem. #15

1.2.4 #

Fixed #

  • A problem that some result in model types are obfuscated when building with Release configuration on Android. #12

1.2.3 #

Fixed #

  • An issue that some classes are stripped unexpectedly when building with release configuration. #10

1.2.2 #

Fixed #

  • An issue that example app crashes when using Flutter SDK 1.12.13. #38464@flutter

1.2.1 #

Fixed #

  • Now currentAccessToken returns null instead of throwing an error when there is no access token stored locally. This behavior now matches what it is done on iOS. #9

1.2.0 #

Added #

  • A parameter for Android to specify the activity request code when login. #4

1.1.0 #

Added #

  • Add idTokenNonce to LoginResult. This value can be used against the ID token verification API as a parameter.

1.0.3 #

Fixed #

  • Improve reference rendering for async APIs.

1.0.2 #

Fixed #

  • Explicitly declare the main dispatcher to run coroutine on Android, which is compatible with changes in the latest flutter. #2

1.0.1 #

Fixed #

  • Internal code formatting and better structure.
  • Improve API reference.

1.0.0 #

  • Initial release of flutter plugin for LINE SDK.


flutter_line_sdk Example #

Demonstrates how to use the flutter_line_sdk plugin.

Getting Started #

To have a quick look at the example app, just execute flutter run under this "example" folder to build it with a simulator target.

By default, this example project is using a public sample channel of LINE SDK. If you want to confirm it on a real device or your own channel, you need:

  1. Register and own a channel from LINE Developers Site and setup everything in the LINE Developers console. For more, read the Getting started with LINE Login guide.

  2. Modify the channel ID in "lib/main.dart" to the ID you want to use.

  3. Modify the iOS Runner project build settings in Xcode to set your app's PRODUCT_BUNDLE_IDENTIFIER, making it match the setting of your channel.

  4. Modify the Android project build settings "android/app/build.gradle" to set your app's applicationId, making it match the setting of your channel.

Now you should be able to try to run the example app with your own channel and devices.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_line_sdk: ^1.2.6

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_line_sdk/flutter_line_sdk.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 21, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Format lib/src/line_sdk.dart.

Run flutter format to format lib/src/line_sdk.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies