Appearance
Flutter Quickstart
Requirements
The Privy Flutter SDK supports:
- Flutter: 3.24.0+
- Dart: 3.0.0+
- Android: API 27+ (Android 8.1 Oreo or newer) and Kotlin 2.1.0+
- iOS: 16+ and SPM
Swift Package Manager
The Privy Flutter SDK uses Swift Package Manager. To enable it, run flutter config --enable-ios-swift-package-manager
.
Note: You'll need to either use Flutter 3.24.0 on the main channel (experimental) or Flutter 3.27.0+ on stable. While 3.24.0 support is available by switching to Flutter's main channel, this is not recommended for production apps as the main channel can be unstable.
Installation
- The Privy Flutter SDK is available on pub.dev. The latest SDK version can be found here.
dependencies:
flutter:
sdk: flutter
privy_flutter: X.Y.Z # Replace with the latest version
- Run
flutter pub get
TIP
Before integrating, you must register your allowed application IDs in the Privy Developer Dashboard, under App Settings > Clients.
Initialization
Initialize a Privy instance with your configuration specified in the PrivyConfig
object.
The configuration fields are:
Field | Type | Required? | Description |
---|---|---|---|
appId | String | Yes | Your Privy application ID, which can be obtained from the Privy Developer Dashboard, under App Settings > Basics |
appClientId | String | Yes | Your app client ID, which can be obtained from the Privy Developer Dashboard, under App Settings > Clients |
logLevel | PrivyLogLevel? | No | (Optional) Your preferred log level. If no log level is specified, it will default to PrivyLogLevel.NONE . |
customAuthConfig | LoginWithCustomAuthConfig? | No | (Optional) Only use this if you plan to use custom authentication. Find more information here. |
dart
import 'package:privy_flutter/privy_flutter.dart';
final privyConfig = PrivyConfig(
appId: "YOUR_APP_ID",
appClientId: "YOUR_CLIENT_ID",
logLevel: PrivyLogLevel.VERBOSE,
);
final privy = Privy(config: privyConfig);
TIP
Be sure to maintain a single instance of Privy across the lifetime of your application. Initializing multiple instances of Privy will result in unexpected errors.
Await Ready
When the Privy SDK is initialized, the user's authentication state will be set to NotReady
until Privy finishes initialization. During this time, we suggest you show a loading state to your user. For you convenience, we've added a suspending awaitReady()
function. Here's an example with some pseudocode:
dart
Future<void> checkPrivyAuth() async {
// Show loading state
setState(() => isLoading = true);
// Wait for Privy SDK to be ready
await privy.awaitReady();
// Privy is ready to use - check if user is authenticated
bool isAuthenticated = privy.authState.isAuthenticated();
// Update UI based on authentication state
setState(() {
isLoading = false;
isUserAuthenticated = isAuthenticated;
});
}
// Example usage in a widget
@override
Widget build(BuildContext context) {
return isLoading
? LoadingScreen()
: (isUserAuthenticated ? AppScreen() : LoginScreen());
}
INFO
Call awaitReady()
to suspend execution until Privy is ready.
That's it! You can now use the Privy SDK to securely authenticate and provision embedded wallets for your users. 🎉