flutter_line_sdk 1.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 91

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.
        print(e);
    }
}

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 #

SettingDescription
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 #

SettingDescription
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:

<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'

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() {
+   LineSDK.instance.setup("1620019587").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) {
  print(e.message);
}

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) {
  print(e.message);
}

Get current stored access token #

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

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) {
  print(e.message);
  // 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) {
  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.

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.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.

example/README.md

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:


dependencies:
  flutter_line_sdk: ^1.2.1

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
81
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
91
Learn more about scoring.

We analyzed this package on Nov 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/src/line_sdk.dart.

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

Dependencies

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.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test