flutter_kakao_login 0.8.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 92

Flutter Kakao Login PlugIn #

A Flutter plugin for using the native Kakao Login SDKs on Android and iOS.

KakaoSDK Version using in plugin #

  • iOS SDK Version 1.21.1
  • Android SDK Version 1.16.0

Required #

  • iOS Required : Deployment Target 9.0 Higher.
  • Android Required : Compile SDK 28 Higher.

Support #

  • AndroidX

Usage #

See example/lib/main.dart for details.

1. Depend on it
Add this to your package's pubspec.yaml file:

dependencies:
  flutter_kakao_login: "^0.8.1"
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_kakao_login/flutter_kakao_login.dart';
  • Login & Logout Example
FlutterKakaoLogin kakaoSignIn = new FlutterKakaoLogin()
final KakaoLoginResult result = await kakaoSignIn.logIn();
switch (result.status) {
    case KakaoLoginStatus.loggedIn:
        _updateMessage('LoggedIn by the user.\n'
                       '- UserID is ${result.account.userID}\n'
                       '- UserEmail is ${result.account.userEmail} ');
    break;
    case KakaoLoginStatus.loggedOut:
        _updateMessage('LoggedOut by the user.');
    break;
    case KakaoLoginStatus.error:
        _updateMessage('This is Kakao error message : ${result.errorMessage}');
    break;
}
  • Unlink Example
Future<Null> _unlink() async {
    await kakaoSignIn.unlink();
    // To-do Someting ...
}
  • Get AccessToken Example
Future<Null> _getAccessToken() async {
    final KakaoAccessToken accessToken = await (kakaoSignIn.currentAccessToken);
    if (accessToken != null) {
      final token = accessToken.token;
      // To-do Someting ...
    }
}
  • Get UserMe Example
Future<Null> _getAccountInfo() async {
    final KakaoLoginResult result = await kakaoSignIn.getUserMe();
    if (result != null && result.status != KakaoLoginStatus.error) {
      final KakaoAccountResult account = result.account;
      final userID = account.userID;
      final userEmail = account.userEmail;
      final userPhoneNumber = account.userPhoneNumber;
      final userDisplayID = account.userDisplayID;
      final userNickname = account.userNickname;
      final userGender = account.userGender;
      final userAgeRange = account.userAgeRange;
      final userBirthday = account.userBirthday;
      final userProfileImagePath = account.userProfileImagePath;
      final userThumbnailImagePath = account.userThumbnailImagePath;
      // To-do Someting ...
    }
  }

Installation #

See the installation by pub.

Android #

See the setup instructions detail.

[kakao_strings.xml]

<resources>
    <string name="kakao_app_key">0123456789abcdefghijklmn</string>
</resources>

[AndroidManifest.xml]

<!-- 1 -->
<uses-permission android:name="android.permission.INTERNET" />

<application>
    <!-- 2 -->
    <activity
        ...
        android:name=".SampleLoginActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!-- 3 -->
    <meta-data
        android:name="com.kakao.sdk.AppKey"
        android:value="@string/kakao_app_key" />
    <!-- 4 -->
    <activity
        android:name="com.kakao.auth.authorization.authcode.KakaoWebViewActivity"
        android:launchMode="singleTop"
        android:windowSoftInputMode="adjustResize">

        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>
    ...
</application>

iOS #

See the setup instructions detail.

[info.plst]

<key>KAKAO_APP_KEY</key>
<string>0123456789abcdefghijklmn</string>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>kakao0123456789abcdefghijklmn</string>
    <string>kakaokompassauth</string>
    <string>storykompassauth</string>
    <string>kakaolink</string>
    <string>storylink</string>
</array>
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string></string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>kakao0123456789abcdefghijklmn</string>
        </array>
    </dict>
</array>

Contributors #

Thank you for your interest in the source and for your help :)

githubemail
@amondamond@amond.net
@myrikyriky@myriky.net
@kunkaamd

[0.0.1] #

  • initial release.

[0.0.2] #

  • how to get accesstoken.

[0.0.3] #

  • kakao android sdk 1.14.0 update.

[0.0.4] #

  • add kakao userme api.

[0.0.5] #

  • add kakao userme api info for android.

[0.0.6] #

  • modify kakao userme api.
  • kakao android sdk 1.16.0 update.
  • kakao ios sdk 1.11.1 update.

[0.0.7] #

  • add ios static_framework true in podspec.

[0.0.8] #

  • update support AndroidX by amond

[0.1.0] #

  • fixed getEmail null exception for android.

[0.1.1] #

  • update document.

[0.2.0] #

  • fixed getKakaoAccount() null exception for android.

[0.3.0] #

  • fixed PluginRegistry ActivityResultListener exception for android. GwonHyeok

[0.4.0] #

  • added kakao unlink feature. amond

[0.5.0] #

  • kakao ios sdk 1.17.2 update.

[0.6.0] #

  • added kakao getGender.
  • migration pre 1.12 android. myriky

[0.7.0] #

  • added kakao getAgeRange, getBirthday.

[0.8.0] #

  • update conflict with multi_image_picker for android kunkaamd

[0.8.1] #

  • update kakao sdk 1.21.1 amond

example/lib/main.dart

import 'dart:async';

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

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

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

class _MyAppState extends State<MyApp> {
  static final FlutterKakaoLogin kakaoSignIn = new FlutterKakaoLogin();

  String _loginMessage = 'Current Not Logined :(';
  String _accessToken = '';
  String _accountInfo = '';
  bool _isLogined = false;

  List<Map<String, String>> _litems = [ { "key": "login", "title": "Login", "subtitle": ""},
                                        { "key": "logout", "title": "Logout", "subtitle": ""},
                                        { "key": "unlink", "title": "Unlink", "subtitle": ""},
                                        { "key": "account", "title": "Get AccountInfo", "subtitle": ""},
                                        { "key": "accessToken", "title": "Get AccessToken", "subtitle": ""} ];

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

  Future<Null> _login() async {
    final KakaoLoginResult result = await kakaoSignIn.logIn();
    _processLoginResult(result);
    //if (result.account != null && result.status != KakaoLoginStatus.error) {
    //  final KakaoAccountResult account = result.account;
    //  _processAccountResult(account);
    //}
  }

  Future<Null> _logOut() async {
    final KakaoLoginResult result = await kakaoSignIn.logOut();
    _processLoginResult(result);
    _processAccountResult(null);
  }

  Future<Null> _unlink() async {
    await kakaoSignIn.unlink();
  }

  Future<Null> _getAccountInfo() async {
    final KakaoLoginResult result = await kakaoSignIn.getUserMe();
    if (result != null && result.status != KakaoLoginStatus.error) {
      final KakaoAccountResult account = result.account;
      _processAccountResult(account);
    }
  }

  Future<Null> _getAccessToken() async {
    final KakaoAccessToken accessToken = await (kakaoSignIn.currentAccessToken);
    if (accessToken != null) {
      final token = accessToken.token;
      _updateAccessToken('AccessToken is \n' + token);
    } else {
      _updateAccessToken('');
    }
  }

  void _updateLoginMessage(String message) {
    setState(() {
      _loginMessage = message;
    });
  }

  void _updateStateLogin(bool logined) {
    setState(() {
      _isLogined = logined;      
    });
    if (!logined) {
      _updateAccessToken('');
      _updateAccountMessage('');
    }
  }

  void _updateAccessToken(String accessToken) {
    setState(() {
      _accessToken = accessToken;
    });
  }

  void _updateAccountMessage(String message) {
    setState(() {
      _accountInfo = message;
    });
  }

  void _processLoginResult(KakaoLoginResult result) {
    switch (result.status) {
      case KakaoLoginStatus.loggedIn:
        _updateLoginMessage('LoggedIn by the user.');

        _updateStateLogin(true);
        break;
      case KakaoLoginStatus.loggedOut:
        _updateLoginMessage('LoggedOut by the user.');

        _updateStateLogin(false);
        break;
      case KakaoLoginStatus.error:
        _updateLoginMessage('This is Kakao error message : ${result.errorMessage}');

        _updateStateLogin(false);
        break;
    }
  }

  void _processAccountResult(KakaoAccountResult account) {
    if (account == null) {
      _updateAccountMessage('');
    } else {
      final userID = (account.userID == null) ? 'None' : account.userID;
      final userEmail = (account.userEmail == null) ? 'None' : account.userEmail;
      final userPhoneNumber = (account.userPhoneNumber == null) ? 'None' : account.userPhoneNumber;
      final userDisplayID = (account.userDisplayID == null) ? 'None' : account.userDisplayID;
      final userNickname = (account.userNickname == null) ? 'None' : account.userNickname;
      final userGender = (account.userGender == null) ? 'None' : account.userGender;
      final userAgeRange = (account.userAgeRange == null) ? 'None' : account.userAgeRange;
      final userBirthday = (account.userBirthday == null) ? 'None' : account.userBirthday;
      final userProfileImagePath = (account.userProfileImagePath == null) ? 'None' : account.userProfileImagePath;
      final userThumbnailImagePath = (account.userThumbnailImagePath == null) ? 'None' : account.userThumbnailImagePath;

      _updateAccountMessage('- ID is ${userID}\n'
                            '- Email is ${userEmail}\n'
                            '- PhoneNumber is ${userPhoneNumber}\n'
                            '- DisplayID is ${userDisplayID}\n'
                            '- Nickname is ${userNickname}\n'
                            '- Gender is ${userGender}\n'
                            '- Age is ${userAgeRange}\n'
                            '- Birthday is ${userBirthday}\n'
                            '- ProfileImagePath is ${userProfileImagePath}\n'
                            '- ThumbnailImagePath is ${userThumbnailImagePath}');
    }
  }

  void _showAlert(BuildContext context, String value) {
    if (value.isEmpty) return;
  
    showDialog(
      context: context, 
      builder: (BuildContext context) { 
        return new AlertDialog(
          content: new Text(
            value,
            style: new TextStyle(fontWeight: FontWeight.bold)
          ),
          actions: <Widget>[
            new FlatButton(
              child: new Text('OK'),
              onPressed: (){
                Navigator.of(context).pop(true);
              },
            )
          ],
        );
      }
    );
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Kakao Login Plugin app'),
        ),
        body: new SafeArea(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[
              new Padding(
                //padding: const EdgeInsets.only(top: 100.0),
                padding: EdgeInsets.all(0.0),
                child: IntrinsicHeight(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch, 
                    children: [
                    Expanded(
                      child: Column(children: [
                        new Container(
                          height: 45.0, 
                          decoration: new BoxDecoration(
                            color: Colors.white,
                            border: new Border(
                              bottom: new BorderSide(color: Colors.white, width: 0.0)
                            )
                          ),
                          child: new Row(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: <Widget>[
                              new Text(
                                "Kakao Login Result",
                                style: new TextStyle(fontWeight: FontWeight.bold)
                              )
                            ],
                          ),
                        ),
                        new Container(
                          height: 250.0, 
                          decoration: new BoxDecoration(
                            color: Colors.white,
                            border: new Border(
                              bottom: new BorderSide(color: Colors.grey, width: 1.0)
                            )
                          ),
                          child: new Center(
                            child: new Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                new Container(
                                  padding: const EdgeInsets.only(top: 5.0, bottom: 5.0, left: 8.0, right: 8.0),
                                  child: new Text(
                                    _loginMessage,
                                    textAlign: TextAlign.left,
                                    overflow: TextOverflow.ellipsis,
                                    maxLines: 10,
                                  ),
                                ),
                                new Container(
                                  padding: const EdgeInsets.only(top: 5.0, bottom: 5.0, left: 8.0, right: 8.0),
                                  child: new Text(
                                    _accountInfo,
                                    textAlign: TextAlign.left,
                                    overflow: TextOverflow.ellipsis,
                                    maxLines: 10,
                                  ),
                                ),
                                new Container(
                                  padding: const EdgeInsets.only(top: 5.0, bottom: 5.0, left: 25.0, right: 25.0),
                                  child: new Text(
                                    _accessToken,
                                    textAlign: TextAlign.left,
                                    overflow: TextOverflow.ellipsis,
                                    maxLines: 10,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                      ]),
                    ),
                  ]),
                )
              ),
              new Expanded(
                child: new ListView.builder (
                    itemCount: _litems.length,
                    itemBuilder: (BuildContext context, int index) {
                      return ListTile(
                        title: new Text(_litems[index]['title']),
                        subtitle: new Text(_litems[index]['subtitle']),
                        onTap: () {
                          final key = _litems[index]['key'];
                          switch (key) {
                            case "login":
                              if (!_isLogined) {
                                _login();
                              }
                            break;
                            case "logout":
                              if (_isLogined) {
                                _logOut();
                              }
                            break;
                            case "unlink":
                              if (_isLogined) {
                                _unlink();
                              }
                            break;
                            case "account":
                              if (!_isLogined) {
                                _showAlert(context, 'Login is required.');
                              } else {
                                _getAccountInfo();
                              }
                            break;
                            case "accessToken":
                              if (!_isLogined) {
                                _showAlert(context, 'Login is required.');
                              } else {
                                _getAccessToken();
                              }
                            break;
                          }
                        },
                      );
                  },
                ),
              ),
            ],
          )
        )
      )
    );
  }
}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

33 out of 33 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

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.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8