JimmyTai / flutter_line_liff

This Flutter plugin is developed for Flutter Web to provide ability to use LINE LIFF SDK.
BSD 3-Clause "New" or "Revised" License
12 stars 5 forks source link

flutter_line_liff

pub package

This Flutter plugin is developed for Flutter Web to provide ability to use LINE LIFF SDK.

- Only Support Web Platform

Usage

To use this plugin, add flutter_line_liff as a dependency in your pubspec.yaml file.

Add Javascript LINE LIFF SDK

Add Javascript dependency in index.html.

<head>
    <script  charset="utf-8"  src="https://static.line-scdn.net/liff/edge/versions/2.20.3/sdk.js"></script>
    <!-- your other html flags -->
</head>

Initialize LIFF SDK

Initialize FlutterLineLiff in main function. Don't initial in Widget.

FlutterLineLiff().init(
    config: Config(liffId: '{YOUR_LIFF_ID}'),
    successCallback: () {},
    errorCallback: (error) {},
);

Wait SDK Ready

You could use all methods in FlutterLineLiff after SDK initialized.

FlutterLineLiff().ready.then((_) {
    // SDK is ready now.
});

Get SDK and Account Information

For all properties detail information, you could find it in LINE LIFF API Reference

// The property that holds the LIFF app ID passed to liff.init()
final String? id = FlutterLineLiff().id;

// Gets the environment in which the user is running the LIFF app.
final String? os = FlutterLineLiff().os;

// Gets the language settings of the environment in which the LIFF app is running.
final String language = FlutterLineLiff().language;

// Gets the version of the LIFF SDK.
final String version = FlutterLineLiff().version;

// Gets the user's LINE version.
final String? lineVersion = FlutterLineLiff().lineVersion;

// Gets the screen type 
// (1-on-1 chat, group chat, multi-person chat, or external browser) 
// from which the LIFF app is launched. 
// For 1-on-1 chats, group chats, and multi-person chats, you also get a unique ID.
final Context? context = FlutterLineLiff().context;

// Determines whether the LIFF app is running in a LIFF browser.
final bool isInClient = FlutterLineLiff().isInClient;

// Checks whether the user is logged in.
final bool isLoggedIn = FlutterLineLiff().isLoggedIn;

// Checks whether the specified API is available in the environment 
// where you started the LIFF app. 
//
// Specifically, it verifies whether the current LINE version 
// supports the API and whether the terms and conditions 
// for the API have been accepted.
// 
// Now [apiName] support: 'shareTargetPicker' | 'multipleLiffTransition'
final bool isApiAvailable = FlutterLineLiff().isApiAvailable(apiName: 'shareTargetPicker');

// Gets the current user's access token.
final String? accessToken = FlutterLineLiff().getAccessToken();

// Get the raw ID token of the current user obtained by the LIFF SDK. 
// An ID token is a JSON Web Token (JWT) that contains user data.
final String? idToken = FlutterLineLiff().getIDToken();

// Gets the payload of the ID token that's acquired by the LIFF SDK. 
// The payload includes information such as user display name, 
// profile image URL, email address, etc.
final JWTPayload? decodedIDToken = FlutterLineLiff().getDecodedIDToken();

Profile

Gets the current user's profile information.

final Profile profile = await FlutterLineLiff().profile;

Friendship

Gets the friendship status between a user and a LINE Official Account.

final Friendship friendship = await FlutterLineLiff().friendship;

Login

Performs the login process in the LINE's in-app browser or external browser.

FlutterLineLiff().login();

FlutterLineLiff().login(
    config: LoginConfig(
        redirectUri: 'xxxxxxxxxx'
    ),
);

Logout

Logs out.

FlutterLineLiff().logout();

Permission

Window

Camera

Launch the 2D code reader and obtain string. To activate the 2D code reader, turn on Scan QRon the LINE Developers Console.

final ScanCodeResult result = await FlutterLineLiff().scanCodeV2();

Message

Permanent Link