flutter_line_login 0.1.3

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 84

flutter_line_login

pub package

A Flutter plugin for allowing users to authenticate with native Android & iOS LINE login SDKs.

Getting Started

Simple code for LINE login:

  var _flutterLineLogin = new FlutterLineLogin();

  await _flutterLineLogin.startWebLogin(
            (data) => {
              // LoginSuccess              
            },
            (error) => {
              // LoginError
            });

}

For more detailed code you need to see an example.

Installation

You'll have to declare a pubspec dependency in your Flutter project. Also some minimal Android & iOS specific configuration must be done.

On your Flutter project

See the installation instructions on pub.

Android

First of all, you need to create a channel for your application in LINE's Developer Console. Please refer to Integrating LINE Login with your Android app and prepare. Once this is done you can get the channel ID.

Next, copy and paste the following into the string resource file.

/android/app/src/main/res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Replace "0000000000" with your LINE Channel ID here. -->
    <string name="line_channel_id">0000000000</string>
</resources>

When the following error occurs at the time of build, it is necessary to make the version of Support Library the same. flutter_line_login dependencies com.android.support: customtabs: 27.1.1.

Caused by: java.lang.RuntimeException: Android dependency 'com.android.support:support-core-utils' has different version for the compile (26.1.0) and runtime (27.1.1) classpath. You should manually set the same version via DependencyResolution

Done!

iOS

First of all, you need to create a channel for your application in LINE's Developer Console. Please refer to Integrate LINE Login with your iOS app and prepare. Once this is done you can get the channel ID.

Next, Set your channel ID in your application’s Info.plist as follows. Make sure you change “1234567890” to the correct channel ID for your channel. Add the required settings for app-to-app login to Info.plist. This lets the user automatically log in to your app if they are logged in to the LINE app.

/ios/Runner/Info.plist

<key>LineSDKConfig</key>
<dict>
    <key>ChannelID</key>
    <!-- Replace "1234567890" with your LINE Channel ID here. -->
    <string>1234567890</string>
</dict>

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
        </array>
    </dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>lineauth</string>
    <string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>

Done!

Usage

Login

Begins the login process. If the LINE app is installed, the SDK defaults to using app-to-app authentication. If it is not installed, the SDK logs in using a web. The login result for LINE app is got by a callback function.

  // Begins the login process.
  await _flutterLineLogin.startLogin(_onLoginSuccess, _onLoginError);

  /// Success callback for LINE login result.
  ///
  /// The data is the map resulting from successful login with LINE login.
  ///
  /// Attributes from LineProfile & LineCredential
  ///
  /// * userID - The user's user ID.
  /// * displayName - The user’s display name.
  /// * pictureUrl - The user’s profile media URL.
  /// * statusMessage - The user’s status message.
  /// * accessToken - User access token.
  /// * expiresIn - The amount of time in milliseconds until the user access token expires.
  /// * permissions - The set of permissions that the access token holds. The following is a list of the permission codes.
  void _onLoginSuccess(Object data) {
    debugPrint("userID:${data['userID']}");
    debugPrint("displayName:${data['displayName']}");
    debugPrint("pictureUrl:${data['pictureUrl']}");
    debugPrint("statusMessage:${data['statusMessage']}");
    debugPrint("accessToken: ${data['accessToken']}.");
    debugPrint("expiresIn: ${data['expiresIn']}.");
  }

  /// Error callback for LINE login result.
  ///
  /// The error is the PlatformException resulting of failing login with LINE login.
  /// Attributes differs between Android and iOS.
  void _onLoginError(Object error) {
    debugPrint("PlatformException: ${error}");
  }

Login with web

Begins the login process. This function uses a Web to log in, not app-to-app authentication.

  await _flutterLineLogin.startWebLogin(_onLoginSuccess, _onLoginError);

The login result is obtained by a callback function. It's same Login.

Logout

Revokes the user access token. If access token is null, PlatformException is throwed.

  // Platform messages may fail, so we use a try/catch PlatformException.
  try {
    await _flutterLineLogin.logout();
    debugPrint("Logout success.");
  } on PlatformException catch (e) {
    debugPrint("PlatformException: ${e}");
  }

Profile

Gets the profile information of the user. If access token is null, PlatformException is throwed.

  // Platform messages may fail, so we use a try/catch PlatformException.
  try {
    var profile = await _flutterLineLogin.getProfile();
    debugPrint("userID:${profile['userID']}");
    debugPrint("displayName:${profile['displayName']}");
    debugPrint("pictureUrl:${profile['pictureUrl']}");
    debugPrint("statusMessage:${profile['statusMessage']}");
  } on PlatformException catch (e) {
    debugPrint("PlatformException: ${e}");
  }

Access Token

Gets the access token for the user. If access token is null, PlatformException is throwed.

  // Platform messages may fail, so we use a try/catch PlatformException.
  try {
    var result = await _flutterLineLogin.currentAccessToken();
    debugPrint("accessToken: ${result['accessToken']}.");
    debugPrint("expiresIn: ${result['expiresIn']}.");
  } on PlatformException catch (e) {
    debugPrint("PlatformException: ${e}");
  }

Verify token

Checks whether the access token for the user is valid. If access token is null, PlatformException is throwed.

  // Platform messages may fail, so we use a try/catch PlatformException.
  try {
    var result = await _flutterLineLogin.verifyToken();
    // Return null only. That means it is successful.
    debugPrint("VerifyToken: ${result == null}.");
  } on PlatformException catch (e) {
    debugPrint("PlatformException: ${e}");
  }

Refresh token

Refreshes the access token for the user. If access token is null, PlatformException is throwed.

  // Platform messages may fail, so we use a try/catch PlatformException.
  try {
    var result = await _flutterLineLogin.verifyToken();
    debugPrint("accessToken: ${result['accessToken']}.");
    debugPrint("expiresIn: ${result['expiresIn']}.");
  } on PlatformException catch (e) {
    debugPrint("PlatformException: ${e}");
  }

LINE SDK has API difference between Android and iOS. So, I did not create all Naive API calling functions. To learn more, you need to look at the Android SDK reference and iOS SDK reference of LINE documentation.

If you find a bug please register issue or Pull Requeste.

Thank you and best regards,

0.1.3

  • Modify README.md

0.1.2

  • Add Pub Icon in README.md
  • Add dart analysis options difines
  • Fix a small code

0.1.1

  • Add Usage in README.md
  • Add docs in code
  • A Small code fix

0.1.0

  • Initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_line_login/flutter_line_login.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  var _flutterLineLogin = new FlutterLineLogin();

  @override
  void initState() {
    super.initState();
  }

  String _message = '';

  set message(String value) {
    setState(() {
      _message = value;
    });
  }

  void _onLoginSuccess(Object data) {
    message = 'LoginSuccess: ${data}.';
  }

  void _onLoginError(Object error) {
    message = 'LoginError: ${error}.';
  }

  Future<Null> _startLogin() async {
    await _flutterLineLogin.startLogin(_onLoginSuccess, _onLoginError);
  }

  Future<Null> _startWebLogin() async {
    await _flutterLineLogin.startWebLogin(_onLoginSuccess, _onLoginError);
  }

  Future<Null> _logout() async {
    try {
      await _flutterLineLogin.logout();
      message = 'Logout:';
    } on PlatformException catch (e) {
      message = 'Logout: ${e}.';
    }
  }

  Future<Null> _getProfile() async {
    try {
      var profile = await _flutterLineLogin.getProfile();
      message = 'Profile: ${profile}.';
    } on PlatformException catch (e) {
      message = 'Profile: ${e}.';
    }
  }

  Future<Null> _currentAccessToken() async {
    var accessToken = await _flutterLineLogin.currentAccessToken();
    message = 'CurrentAccessToken: ${accessToken}.';
  }

  Future<Null> _verifyToken() async {
    try {
      var result = await _flutterLineLogin.verifyToken();
      message = 'VerifyToken: ${result}.';
    } on PlatformException catch (e) {
      message = 'VerifyToken: ${e}.';
    }
  }

  Future<Null> _refreshToken() async {
    try {
      var result = await _flutterLineLogin.refreshToken();
      message = 'RefreshToken: ${result}.';
    } on PlatformException catch (e) {
      message = 'RefreshToken: ${e}.';
    }
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Flutter Line Login Demo'),
        ),
        body: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Row(
                children: <Widget>[
                  RaisedButton(
                      child: Text('Login'), onPressed: () => _startLogin()),
                  RaisedButton(
                      child: Text('WebLogin'),
                      onPressed: () => _startWebLogin()),
                  RaisedButton(
                      child: Text('Logut'), onPressed: () => _logout()),
                ],
              ),
              RaisedButton(
                  child: Text('GetProfile'), onPressed: () => _getProfile()),
              RaisedButton(
                child: Text('CurrentAccessToken'),
                onPressed: () => _currentAccessToken(),
              ),
              RaisedButton(
                child: Text('VerifyToken'),
                onPressed: () => _verifyToken(),
              ),
              RaisedButton(
                child: Text('RefreshToken'),
                onPressed: () => _refreshToken(),
              ),
              Expanded(
                flex: 1,
                child: SingleChildScrollView(
                  child: Text(_message,
                      style: TextStyle(color: Color.fromARGB(255, 0, 155, 0))),
                ),
              )
            ]),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_line_login: ^0.1.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages 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_login/flutter_line_login.dart';
  
Version Uploaded Documentation Archive
0.1.3 Aug 1, 2018 Go to the documentation of flutter_line_login 0.1.3 Download flutter_line_login 0.1.3 archive
0.1.2 Jul 28, 2018 Go to the documentation of flutter_line_login 0.1.2 Download flutter_line_login 0.1.2 archive
0.1.1 Jul 28, 2018 Go to the documentation of flutter_line_login 0.1.1 Download flutter_line_login 0.1.1 archive
0.1.0 Jul 27, 2018 Go to the documentation of flutter_line_login 0.1.0 Download flutter_line_login 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
69
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]
84
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8