Optare v1.0 is now available. Get started →
Quickstarts
Flutter

Add Login to Your Flutter App

This quickstart shows how to integrate Optare ID with Flutter for iOS and Android.

Prerequisites

  • Flutter 3.0+ installed
  • An Optare account
  • A Flutter project

1. Install the SDK

Add to pubspec.yaml:

dependencies:
  optareid_flutter: ^0.1.4

Then run:

flutter pub get

2. Get Your Client ID

  1. Log in to Optare Console (opens in a new tab)
  2. Create an OAuth client with:
    • Application Type: Native/Mobile
    • Redirect URI: com.yourcompany.yourapp://callback
  3. Copy the Client ID

3. Configure Deep Links

Android

Add to android/app/src/main/AndroidManifest.xml:

<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data
    android:scheme="com.yourcompany.yourapp"
    android:host="callback" />
</intent-filter>

iOS

Add to ios/Runner/Info.plist:

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>com.yourcompany.yourapp</string>
    </array>
  </dict>
</array>

4. Initialize the SDK

import 'package:optareid_flutter/optareid_flutter.dart';
 
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  await OptareId.initialize(
    domain: 'https://id.optare.one',
    clientId: 'your_client_id',
    redirectUri: 'com.yourcompany.yourapp://callback',
  );
  
  runApp(MyApp());
}

5. Add Login Button

import 'package:optareid_flutter/optareid_flutter.dart';
 
class LoginScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () async {
            try {
              await OptareId.login();
              Navigator.pushReplacementNamed(context, '/home');
            } catch (e) {
              print('Login failed: $e');
            }
          },
          child: Text('Log In'),
        ),
      ),
    );
  }
}

6. Check Auth State

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: FutureBuilder<bool>(
        future: OptareId.isAuthenticated(),
        builder: (context, snapshot) {
          if (snapshot.data == true) {
            return HomeScreen();
          }
          return LoginScreen();
        },
      ),
    );
  }
}

7. Get User Info

final user = await OptareId.getUser();
 
print('Email: ${user.email}');
print('Name: ${user.name}');
print('Organization: ${user.organizationId}');

8. Logout

await OptareId.logout();
Navigator.pushReplacementNamed(context, '/login');

9. Check Licenses

final hasFeature = await OptareId.hasLicense('premium-feature');
 
if (hasFeature) {
  // Show premium feature
}

Secure Token Storage

The SDK automatically uses flutter_secure_storage to securely store tokens:

  • iOS: Keychain
  • Android: EncryptedSharedPreferences

Next Steps