kakao_flutter_sdk 0.3.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 85

kakao_flutter_sdk #

Flutter SDK for Kakao API. Currently supports Android and iOS platform, and will support web platform (still in technival preview stage) when it becomes stable.

Getting Started #

Flutter is becoming more wide-spread as a cross-platform development tool since it provides natively-compiled applications for mobile, web, and desktop from a single codebase. Several requests have been made for Flutter support for Kakao API.

Setting up the dependency #

The first step is to include Kakao Flutter SDK into your project, in pubspec.yaml. Currently, Kakao Flutter SDK is not publicly released on pub.dev. Therefore, you have to specify the dependency as below in your pubspec.yaml.

dependency_overrides:
  kakao_flutter_sdk:
    git:
      url: git@github.com:CoderSpinoza/kakao-flutter-sdk.git

In the near future when it is released on pub.dev, below would suffice.

dependencies:
  kakao_flutter_sdk: ^0.3.1

Transitive dependencies #

Kakao Flutter SDK has following transitive dependencies:

  1. dio (2.1.0)
  2. json_serializable (2.4.0)
  3. shared_preferences (0.5.3+1)
  4. platform (2.2.0)

Below dependencies were considered but was removed due to restrictions against our needs:

  1. url_launcher
  2. flutter_custom_tabs
  3. flutter_web_auth

SDK calls Chrome Custom Tabs and ASWebAuthenticationSession natively via platform channel.

Set up your Kakao App #

You have to create an application on Kakao Developers and set up iOS and Android platforms. Follow the instructions below:

  1. Getting Started on Android
  2. Getting Started on iOS

Implementation Guide #

Initializing SDK #

First, you have to initialize SDK at app startup in order to use it. It is as simple as setting your native app key in global context.

KakaoContext.clientId = "${put your native app key here}"

Kakao Login #

First, users have to get access token in order to call Kakao API. Access tokens are issued according to OAuth 2.0 spec.

  1. kakao account authentication
  2. user agreemnet (skip if not necessary)
  3. get authorization code (via redirect)
  4. issue access token (via POST API)

Getting Authorization Code #

There are two ways users can get authorization code.

  1. Via kakao account login in browser
  2. Via KakaoTalk
Via browser #

SDK uses ASWebAuthenticationSession and Custom Tabs for opening browser on iOS and Android, respectively.

void loginButtonClicked() async {
  try {
    String authCode = await AuthCodeClient.instance.request();
  } on KakaoAuthException catch (e) {
    // some error happened during the course of user login... deal with it.
  } on KakaoClientException catch (e) {
    //
  } catch (e) {
    //
  }
}
Via KakaoTalk #
void loginButtonClicked() async {
  try {
    String authCode = await AuthCodeClient.instance.requestWithTalk();
  } on KakaoAuthException catch (e) {
    // some error happened during the course of user login... deal with it.
  } on KakaoClientException catch (e) {
    //
  } catch (e) {
    //
  }
}

Getting Access Token #

Sample login code is pasted below:

void loginButtonClicked() async {
  try {
    String authCode = await AuthCodeClient.instance.request();
    AccessToken token = await AuthApi.instance.issueAccessToken(authCode);
    AccessTokenStore.instance.toCache(token);
  } catch (e) {
    // some error happened during the course of user login... deal with it.
  }
}

Currently, Kakao Flutter SDK does not plan to support Kakao login or KakaoLink via kakaoTalk. The SDK tries to support as many platform and environment as possible and mobile-only

After user's first login (access token persisted correctly), you can check the status of AccessTokenStore in order to skip this process. Below is the sample code of checking token status and redirecting to login screen if refresh token does not exist.

String token = await AccessTokenStore.instance.fromCache();
if (token.refreshToken == null) {
  Navigator.of(context).pushReplacementNamed('/login');
} else {
  Navigator.of(context).pushReplacementNamed("/main");
}

Existence of refresh token is a good criteria for deciding whether user has to authorize again or not, since refresh token can be used to refresh access token.

Calling Token-based API #

After ensuring that access token does exist with above step, you can call token-based API. Below are set of APIs that are currently supported with Kakao Flutter SDK.

  1. UserApi
  2. TalkApi
  3. StoryApi

Tokens are automatically added to Authorization header by AccessTokenInterceptor.

Below is an example of calling /v2/user/me API with UserApi class.

try {
  User user = await UserApi.instance.me();
  // do anything you want with user instance
} on KakaoAuthException catch (e) {
  if (e.code == ApiErrorCause.INVALID_TOKEN) { // access token has expired and cannot be refrsehd. access tokens are already cleared here
    Navigator.of(context).pushReplacementNamed('/login'); // redirect to login page
  }
} catch (e) {
  // other api or client-side errors
}

App key based API #

KakaoLink API can be used after simply setting your native app key in KakaoContext since it is not a token-based API. Below is an example of sending KakaoLink message with custom template.

import 'package:kakao_flutter_sdk/main.dart';

Uri uri = await LinkClient.instance
          .custom(16761, templateArgs: {"key1": "value1"});
await launchBrowserTab(uri);

SDK Architecture #

Automatic token refreshing #

Tokens are automatically refreshed on relveant api errors.

Dynamic User Agreement #

There are

Customization #

Documentation #

Docs are generated by DartDoc and currently published under https://coderspinoza.github.io/kakao-flutter-sdk/. This documentation page is going to be maintained apart from the page that will be available on pub.dev

Development Guide #

$ flutter analyze --no-pub --no-current-package lib
$ flutter packages pub publish --dry-run

Defining Response Models #

$ flutter packages pub run build_runner build --delete-conflicting-outputs

0.3.1 #

  • Minor fixes
  • fix wrong json keys for androidExecParams and iosExecParms in Link class of template module.

0.3.0 #

  • Release according to recent Kakao API udpate.
  • Add message send API to TalkApi. Also update Friend model to include uuid and favorite field.
  • Add live account profile data to Account and groupUserToken field to User.

0.2.3 #

  • Provide presentationContextProvider to ASWebAuthenticationSession in login. (fix for iOS13.0)
  • Make isRetryable method of AccessTokenInterceptor public so that the interceptor can be used in a customized way. Third-party can override this method for their own API client if Authorization header matches the format Bearer ${kakao_access_token} for their API (which is a very uncommon need).

0.2.2 #

  • Update dio package to 3.0.0 and fix compile errors due to interface changes. Changes that were merged in 2.2.1 were ported to 3.0.0, presumably to ensure version compatibility in ^2.2.x.

0.2.1 #

  • Stabilize agains flutter 1.9.1.
  • Update dio package to 2.2.1 and fix compile errors due to interface changes.

0.2.0 #

  • SDK for Kakao Search API
  • SDK for Kakao Local API
  • Set secure_resource to true for /v2/user/me API.

0.1.2 #

  • Remove meta package from expliciit dependency.

0.1.1 #

  • Update description field in pubspec.yaml to be longer than 60 characters.
  • Update meta package version from 1.1.6 to 1.1.7.

0.1.0 #

  • Kakao Flutter SDK Initial Release

example/README.md

kakao_flutter_sdk_example #

Demonstrates how to use the kakao_flutter_sdk plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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


dependencies:
  kakao_flutter_sdk: ^0.3.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:kakao_flutter_sdk/auth.dart';
import 'package:kakao_flutter_sdk/common.dart';
import 'package:kakao_flutter_sdk/link.dart';
import 'package:kakao_flutter_sdk/local.dart';
import 'package:kakao_flutter_sdk/push.dart';
import 'package:kakao_flutter_sdk/search.dart';
import 'package:kakao_flutter_sdk/story.dart';
import 'package:kakao_flutter_sdk/talk.dart';
import 'package:kakao_flutter_sdk/template.dart';
import 'package:kakao_flutter_sdk/user.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
70
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]
85
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
dio ^3.0.3 3.0.3
flutter 0.0.0
json_annotation ^3.0.0 3.0.0
package_info ^0.4.0 0.4.0+9
platform ^2.2.1 2.2.1
shared_preferences ^0.5.3 0.5.3+5
Transitive dependencies
charcode 1.1.2
collection 1.14.11 1.14.12
http_parser 3.1.3
meta 1.1.7
path 1.6.4
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
build_runner ^1.0.0
flutter_test
json_serializable ^3.2.3