Skip to main content

Flutter Quickstart

Cloud has the newest features. Some may not be in a release yet; the newest release is Identity & Access Management 7.3.0.

Use this guide to add Choreo Identity & Access Management authentication to a Flutter application using the thunderid_flutter package.

Get the complete sample

What You Will Learn​

  • Create a new Flutter project
  • Install the thunderid_flutter package
  • Add working sign-in and sign-out using Flutter widgets
  • Display the signed-in user's name

Prerequisites​

  • About 20 minutes
  • Flutter 3.16+ and Dart 3.2+
  • iOS 16+ or Android API 26+ target device or simulator

Create an Application​

  1. Sign in to the Console at https://console.cloud.choreolabs.com/iam/. Select your project in the project switcher in the header.
  2. Navigate to Applications.
  3. Click Add application.
  4. From the Choose a type page, select Flutter.
  5. Enter a name (e.g. My Flutter App).
  6. Select how you want to sign in users (e.g., email/password, social login, etc.).
  7. Select Theme settings.
  8. Leave Sign-in approach set to Bring your own UI (the default for Flutter applications).
  9. Click Create.
warning

Copy the Application ID from the General tab, under Quick copy. You'll need it when configuring the SDK.

  1. Open the Advanced Settings tab, turn on Dev mode under Platform attestation, then click Save.
Platform attestation

Mobile applications prove their binary identity before starting a sign-in flow. If platform attestation is not configured and Dev mode is off, sign-in fails with FES-1016, Attestation not configured. Dev Mode is a bypass for local development; configure platform attestation for production.

Data plane URL

Code in this guide uses https://<DATA_PLANE_URL> for your environment's data plane URL, where users sign in and tokens are issued. Replace it with the URL on the environment's Endpoints page. To open it, select your project, go to Deployment pipeline, and click Open environment on the environment's card. See Control Plane and Data Plane URLs.

Deploy your changes

Saving a change does not make it live. You author in the control plane, and your users sign in on a separate data plane, so a change takes effect in an environment only after you deploy it. Go to Deploy, deploy the latest version to your first environment, then promote it to the next environment when you are ready.

Auto-sync deploys saved changes to your first environment within seconds. Turning it on is your choice, per project. See Deploy a Version, or learn why you deploy and how auto-sync works.

Create a Flutter App​

Create a new Flutter project:

flutter create my_flutter_app
cd my_flutter_app
note

If you already have an existing Flutter project, skip this step.

Install thunderid_flutter Package​

Add the package, which writes a version constraint to your pubspec.yaml and records the resolved version in pubspec.lock:

flutter pub add thunderid_flutter

Configure the Platforms​

The flutter create template does not include the configuration the plugin needs.

For Android, add the JitPack repository, which hosts the plugin's native dependency:

android/build.gradle.kts
allprojects {
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}

Then replace the template's minSdk = flutter.minSdkVersion with 26, which the plugin requires:

android/app/build.gradle.kts
android {
defaultConfig {
minSdk = 26
}
}

For iOS, build with CocoaPods rather than Swift Package Manager. This also generates ios/Podfile, which the next step edits:

flutter config --no-enable-swift-package-manager
flutter pub get

Then set the platform to 16 and add the native SDK as a Git pod:

ios/Podfile
platform :ios, '16.0'

# ...

target 'Runner' do
use_frameworks!

pod 'ThunderID', :git => 'https://github.com/thunder-id/ios-sdks', :branch => 'main'

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

Initialize the SDK​

Wrap your root widget with ThunderIDProvider in lib/main.dart:

lib/main.dart
import 'package:flutter/material.dart';
import 'package:thunderid_flutter/thunderid_flutter.dart';
import 'root_screen.dart';

void main() {
runApp(
ThunderIDProvider(
config: ThunderIDConfig(
baseUrl: 'https://<DATA_PLANE_URL>',
scopes: const ['openid', 'profile', 'email'],
applicationId: '<your-application-id>',
),
child: const MyApp(),
),
);
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return const MaterialApp(
home: RootScreen(),
);
}
}
Configuration

Replace <your-application-id> with the Application ID from your Choreo Identity & Access Management application settings.

Configuration Parameters​

ParameterDescription
baseUrlYour Choreo Identity & Access Management instance URL. Must use HTTPS.
scopesOAuth 2.0 scopes to request. Include 'openid' at minimum.
applicationIdThe Application ID used for the app-native sign-in and sign-up flows

Add Sign-In and Sign-Out​

Create a root screen that reads auth state from ThunderIDProvider.of(context) and routes to either your auth or home screen.

Create lib/root_screen.dart:

lib/root_screen.dart
import 'package:flutter/material.dart';
import 'package:thunderid_flutter/thunderid_flutter.dart';
import 'auth_screen.dart';
import 'home_screen.dart';

class RootScreen extends StatelessWidget {
const RootScreen({super.key});

@override
Widget build(BuildContext context) {
final thunder = ThunderIDProvider.of(context);

if (!thunder.initialized || thunder.isLoading) {
return const Scaffold(
body: Center(child: CircularProgressIndicator()),
);
}

return thunder.isSignedIn ? const HomeScreen() : const AuthScreen();
}
}

Create lib/auth_screen.dart to display the sign-in form:

lib/auth_screen.dart
import 'package:flutter/material.dart';
import 'package:thunderid_flutter/thunderid_flutter.dart';

enum _AuthMode { signIn, signUp }

class AuthScreen extends StatefulWidget {
const AuthScreen({super.key});

@override
State<AuthScreen> createState() => _AuthScreenState();
}

class _AuthScreenState extends State<AuthScreen> {
_AuthMode _mode = _AuthMode.signIn;

@override
Widget build(BuildContext context) {
const applicationId = '<your-application-id>';

return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 40),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SegmentedButton<_AuthMode>(
segments: const [
ButtonSegment(value: _AuthMode.signIn, label: Text('Sign In')),
ButtonSegment(value: _AuthMode.signUp, label: Text('Create Account')),
],
selected: {_mode},
onSelectionChanged: (s) => setState(() => _mode = s.first),
),
const SizedBox(height: 28),
if (_mode == _AuthMode.signIn)
SignIn(applicationId: applicationId)
else
SignUp(applicationId: applicationId),
],
),
),
),
);
}
}
Configuration

Replace <your-application-id> with the Application ID from your Choreo Identity & Access Management application settings.

Display User Profile Information​

Create lib/home_screen.dart to show the authenticated user's name and a sign-out button:

lib/home_screen.dart
import 'package:flutter/material.dart';
import 'package:thunderid_flutter/thunderid_flutter.dart';

class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});

@override
Widget build(BuildContext context) {
final thunder = ThunderIDProvider.of(context);
final user = thunder.user;

return Scaffold(
appBar: AppBar(title: const Text('Home')),
body: Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (user != null) ...[
Text(
'Welcome, ${user.displayName ?? user.email ?? 'User'}!',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Text(
user.email ?? '',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 24),
],
SignOutButton(),
],
),
),
);
}
}

Run the App​

Start an iOS simulator or connect an Android device, then run:

flutter run
Test credentials

You'll need a user to sign in with. If you haven't created one yet, open https://console.cloud.choreolabs.com/iam/, navigate to Users, and add a test user with an email and password.

Success

You should see the sign-in form. Enter your test user credentials and tap Submit. After successful authentication, the home screen displays the user's name and a Sign Out button.

Run the Sample App​

The Flutter sample is a working version of the app this guide builds. To run it instead of building the app yourself:

  1. Download the sample from its releases and open its folder.

  2. Create .env in the sample's folder with your application's values:

    .env
    THUNDERID_BASE_URL=https://<DATA_PLANE_URL>
    THUNDERID_APP_ID=<your-application-id>
  3. Install the dependencies and run the app:

    flutter pub get
    flutter run

What's Next​

Was this page helpful?