flutter_linkedin_login 1.0.0

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

flutter_linkedin_login

A Flutter plugin for Sign in with LinkedIn

Installation

See the installation instructions on pub

Android

Follow the "Associate your Android app with your LinkedIn app" section of LinkedIn's Getting started with Android. Find your package name in the android/app/src/main/AndroidManifest.xml file. For the debug key hash value generation, remember to use 'android' as your password. Click update after adding your package and key in LinkedIn's developer console for your changes to take.

Open your MainActivity in your Android app/src/main/ directory and override the onActivityResult method with the following

//kotlin
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
  FlutterLinkedinLoginPlugin.onActivityResult(this, requestCode, resultCode, data)
  super.onActivityResult(requestCode, resultCode, data)
}
//java
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  FlutterLinkedinLoginPlugin.onActivityResult(this, requestCode, resultCode, data);
  super.onActivityResult(requestCode, resultCode, data);
}

iOS

Follow the "Associate your iOS app with your LinkedIn app" section of LinkedIn's Getting started with iOS.

Open your AppDelegate in your ios/Runner directory and add the following function

//swift
//add #import <flutter_linkedin_login/FlutterLinkedinLoginPlugin.h>
//to your Running-Bridging-Header.h file
override func application(_ app: UIApplication, open: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    if (FlutterLinkedinLoginPlugin.shouldHandle(open)) {
        return FlutterLinkedinLoginPlugin.application(app, open: open, sourceApplication: nil, annotation: nil)
    }
    return true
}
//objective-c
//add #import <flutter_linkedin_login/FlutterLinkedinLoginPlugin.h> at top of your AppDelegate.m
- (BOOL)application:(UIApplication *)application open:(NSURL *)open options:(UIApplicationOpenURLOptionsKey *)options {
    if ([FlutterLinkedinLoginPlugin shouldHandleUrl:url]) {
        return [FlutterLinkedinLoginPlugin application:application open:open sourceApplication:nil annotation: nil];
    }
    return YES;
}

Usage

Signing in

FlutterLinkedInLogin.login will check if an access token is still valid on the device. If not, then it will proceed with LinkedIn's sign in process. Login will throw exceptions with code detailed here. A user can either cancel login or cancel authorization.

  _signInWithLinkedIn() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      String status = await FlutterLinkedinLogin.login;
      debugPrint("login status: $status");
    } on PlatformException catch(e) {
      debugPrint("PlatformException code: ${e.code}, message: ${e.message}, toString: ${e.toString()}");
    }
  }

Getting LinkedIn Profile

FlutterLinkedinLogin.profile will retrieve the user's basic profile which includes their LinkedIn id, first name, last name, headline, industry, summary, and pictureUrl. Profile will communicate errors via http status codes as documented here.

  _getProfile() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      LinkedInProfile profile = await FlutterLinkedinLogin.profile;
      debugPrint("profile: $profile");
    } on PlatformException catch(e) {
      debugPrint("PlatformException httpStatusCode: ${e.code}, message: ${e.message}, toString: ${e.toString()}");
    }
  }

Clearing session

FlutterLinkedinLogin.clearSession clears the users access token, essentially logging them out. Even if a token doesn't exist, clearSession will return a success with message 'No session', therefore a PlatformException should never be thrown by clearSession.

  _clearSession() async {
    try {
      String status = await FlutterLinkedinLogin.clearSession;
      debugPrint("logout status: $status");
    } on PlatformException catch(e) { //This should never happen
      debugPrint("PlatformException code: ${e.code}, message: ${e.message}, toString: ${e.toString()}");
    }
  }

Additional API calls

Submit an issue if you would like to see additional LinkedIn APIs exposed. This simple implementation was enough for my purposes.

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

1.0.0 - 2018-07-22

Added

  • Support for iOS

Changed

  • Android check session valid before getting profile

0.1.1 - 2018-07-22

Changed

  • Android MainActivity must override onActivityResult

0.0.1 - 2018-07-04

Added

  • Support for Android

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_linkedin_login/flutter_linkedin_login.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _loginStatus = 'Press button to log in';


  _signInWithLinkedIn() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      String status = await FlutterLinkedinLogin.login;
      setState(() {
        _loginStatus = status;
      });
    } on PlatformException catch(e) {
      debugPrint("PlatformException code: ${e.code}, message: ${e.message}, toString: ${e.toString()}");
      setState(() {
        _loginStatus = "code: ${e.code}, message: ${e.message}";
      });
    }
  }

  _getProfile() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      LinkedInProfile profile = await FlutterLinkedinLogin.profile;
      debugPrint("profile: $profile");
      setState(() {
        _loginStatus = profile.firstName;
      });
    } on PlatformException catch(e) {
      debugPrint("PlatformException code: ${e.code}, message: ${e.message}, toString: ${e.toString()}");
      setState(() {
        _loginStatus = "code: ${e.code}, message: ${e.message}";
      });
    }
  }

  _clearSession() async {
    try {
      String status = await FlutterLinkedinLogin.clearSession;
      debugPrint("logout status: $status");
      setState(() {
        _loginStatus = status;
      });
    } on PlatformException catch(e) {
      debugPrint("PlatformException code: ${e.code}, message: ${e.message}, toString: ${e.toString()}");
      setState(() {
        _loginStatus = "code: ${e.code}, message: ${e.message}";
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('LinkedIn Login Plugin Example'),
        ),
        body: new Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            new Text('Login status: $_loginStatus\n'),
            new RaisedButton(
              onPressed: _signInWithLinkedIn,
              child: new Text("Log into LinkedIn"),
            ),
            new RaisedButton(
              onPressed: _getProfile,
              child: new Text("Get Profile"),
            ),
            new RaisedButton(
              onPressed: _clearSession,
              child: new Text("Clear Session"),
            )
          ]
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_linkedin_login: ^1.0.0

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_linkedin_login/flutter_linkedin_login.dart';
  
Version Uploaded Documentation Archive
1.0.0 Jul 22, 2018 Go to the documentation of flutter_linkedin_login 1.0.0 Download flutter_linkedin_login 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.11.8
  • Flutter: 0.5.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

Format lib/flutter_linkedin_login.dart.

Run flutter format to format lib/flutter_linkedin_login.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.6 1.14.11
meta 1.1.5 1.1.6
sky_engine 0.0.99
typed_data 1.1.5 1.1.6
vector_math 2.0.6 2.0.8