Flutter Setup

Introduction

The Capsule SDK for Flutter allows you to easily integrate secure and scalable wallet functionalities into your mobile applications. This guide covers the installation, setup, and usage of the Capsule SDK, including handling authentication flows.

Prerequisites

Installation

Dependency Installation

To install the Capsule SDK and required dependencies, use the following command:

flutter pub add capsule

Setup

Follow these steps to properly set up Capsule SDK in your project.

1. Initialize the Capsule SDK

In your Flutter project, import the Capsule package and initialize it in your app.

main.dart
import 'package:capsule/capsule.dart';

class MyAppState extends State<MyApp> {
  late Capsule _capsule;

  @override
  void initState() {
    super.initState();
    _capsule = Capsule(
      environment: Environment.beta,
      apiKey: 'YOUR_API_KEY',
    )..init();
  }

  @override
  void dispose() {
    _capsule.dispose();
    super.dispose();
  }
}

2. User and Wallet Creation

To handle user and wallet creation, use the following code snippets as a reference.

main.dart
Future<void> signUp(String email, String verificationCode) async {
  final userExists = await _capsule.checkIfUserExists(email);
  if (!userExists) {
    await _capsule.createUser(email);
    final biometricsId = await _capsule.verifyEmail(verificationCode);
    await _capsule.generatePasskey(email, biometricsId);
    final wallet = (await _capsule.createWallet(
      skipDistribute: false,
    )).wallet;
    // Store or display the recovery key
  }
}

3. User Login

To handle user login, use the following code snippet:

main.dart
Future<void> login(String email) async {
  final passkeyUrl = await _capsule.initiateUserLogin(email);
  // Direct user to the passkey URL to authenticate
  await _capsule.waitForLoginAndSetup();
}

Examples and Next Steps

While the Flutter SDK does not have the extensive customization options available in the web SDK, you can still effectively integrate and use it in your Flutter applications. We encourage you to explore our example repository for practical implementations and signing solutions:

urlhttps://github.com/capsule-org/flutter-example

This example provides a comprehensive guide on how to handle user authentication, wallet creation, and signing messages using the Capsule SDK in a Flutter application. Following this example will help you understand how to integrate Capsule into your project seamlessly.

For more additional integration details, refer to the:

page❗Required Customization

Last updated