As you all know, Facebook Account Kit - powered by Facebook - lets you quickly register for and login to your app by using just user's phone number. It's reliable and easy to integrate. Now it's is available in Flutter.
- Access Facebook Developer : https://developers.facebook.com
- Create new app
- Add AccountKit to your Facebook Developer project
- Open your project, create
strings.xml
file at this path:\android\app\src\main\res
- Add 2 variables like below:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="FACEBOOK_APP_ID" translatable="false">[YOUR_FACEBOOK_APP_ID]</string>
<string name="ACCOUNT_KIT_CLIENT_TOKEN" translatable="false">[ACCOUNT_KIT_CLIENT_TOKEN]</string>
</resources>
About the Facebook App ID and Account Kit Client Token, please keep reading
- Set up your AndroidManifest.xml in
/android/app/src/main
. Full code here.
- Open
ios\Runner\Info.plist
by right click -> open by source code - Copy and paste this inside the space between <dict></dict> tag.
<key>FacebookAppID</key>
<string>[YOUR_FACEBOOK_APP_ID]</string>
<key>AccountKitClientToken</key>
<string>[ACCOUNT_KIT_CLIENT_TOKEN]</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>ak[YOUR_FACEBOOK_APP_ID]</string>
</array>
</dict>
</array>
YOUR_FACEBOOK_APP_ID: you can get it in picture below and simply press to copy ACCOUNT_KIT_CLIENT_TOKEN:
... It's done for configuration !! Let's go back to Flutter main.dart
It's very easy !!!
dependencies:
fb_accountkit_flutter: ^0.0.2
And do not forget to call flutter get
to get the dependency in pub.dev
import 'package:fb_accountkit_flutter/fb_accountkit_flutter.dart';
Result result = await FbAccountkitFlutter.startAuthentication()
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:fb_accountkit_flutter/fb_accountkit_flutter.dart';
Future<void> openFacebookActivity() async {
Result result;
try {
FbAccountkitFlutter.defaultCountryCode = "[YOUR DEFAULT COUNTRY CODE]"; // Ex: US, AL etc.
// Find more here : https://developers.facebook.com/docs/accountkit/countrycodes/
FbAccountkitFlutter.codeIso = "[YOUR ISO CODE]"; // Ex: 93, 355 etc.
// Find Dialing Code here : https://developers.facebook.com/docs/accountkit/countrycodes/
FbAccountkitFlutter.countryCode = "[YOUR COUNTRY CODE]";
// Find A 3 in here : http://kirste.userpage.fu-berlin.de/diverse/doc/ISO_3166.html
// Optional
FbAccountkitFlutter.phone = "[INITIAL PHONE]";
// Request open accountkit
result = await FbAccountkitFlutter.startAuthentication();
} on PlatformException catch(e) {
print(e);
result = null;
}
}
You can read the full code in the example package also.