Skip to content

Get Started: Flutter Apps

Estimated time to read: 3 minutes

Integrate 'Flutter' apps with Arcana Auth Flutter SDK and onboard users via social login. Enable users to sign blockchain transactions with the in-app Arcana wallet.

Prerequisites

Flutter Version

We support Flutter v3.15.0 or higher

2. Install

The Arcana Auth Flutter SDK is a Flutter plugin. It is available for download at 'Pub.dev' as the arcana_auth_flutter package.

Add the following line to the dependencies section in your app's pubspec.yaml file:

pubspec.yaml
dependencies:
  flutter:       # Required for every Flutter project
    sdk: flutter # Required for every Flutter project
  flutter_localizations: # Required to enable localization
    sdk: flutter         # Required to enable localization
  arcana_auth_flutter: ^0.0.6 # Required for integrating with Arcana Auth SDK

2. Integrate

import 'package:arcana_sdk/arcana_sdk.dart';

final auth = AuthProvider(clientId:"xar_xxxx_...");
auth.init(context: context);

Onboard Users

auth.loginWithSocial("google").then((_) => {
// On login Success
}).catchError(...);

Sign Transactions

The AuthProvider supports the JSON-RPC requests for the following Web3 operations in Flutter apps:

auth.request(method: "...", params: [...]).then(() => ...);
auth.sendTransaction({ to: "", value: "" }).then((hash) => ...);

That's all!

The 'Flutter' app is ready to onboard users and allow them to sign blockchain transactions.

4. Advanced Usage

Flutter SDK Usage

Social Login

auth.loginWithSocial("google").then((_) => {
// On login Success
}).catchError(...);

OTP Login

auth.loginWithOTP("${email_id}").then((_) => {
// On login Success
}).catchError(...);

Logout

auth.logout().then((_) => {
// On logout
});

Get User Address

auth.getAccount().then((account) => ...);

Get User Details

auth.getUserInfo().then((UserInfo info) => ...);

Show/Hide Wallet UI

auth.showWallet();
auth.hideWallet();

Check Wallet Visibility

var isVisible = auth.isVisible();

Clear Cache

auth.clearCache();
Arcana JWT Token

Upon successful authentication, Arcana Auth SDK returns a unique JWT token to the app called the Arcana JWT Token. App developers can access this token via getUser() method and refer to the loginToken field of the UserInfo object.

Developers can use this token to verify the user and subsequently generate another token for app use if required.

In the future, the Arcana JWT Token will be deprecated. Use userDIDToken to verify user.

Upon successful authentication, Arcana Auth SDK returns a unique DID token to the app called the Arcana DID Token. App developers can access this token via getUser() method and refer to the userDIDToken field of the UserInfo object.

Developers can use this token to verify the user and subsequently generate another token for app use.

See also

'Flutter' integration example: See sample-auth-flutter submodule in Auth Examples

Arcana Auth Flutter SDK Quick Links

Try Demo App!


Last update: July 11, 2024 by shaloo, shaloo