Flutter Quickstart
Add authentication and user management to your Flutter app with Clerk.
Enable Native API
In the Clerk Dashboard, navigate to the Native applications page and ensure that the Native API is enabled. This is required to integrate Clerk in your native application.
Create a new Flutter app
-
If you don't already have a Flutter app, first follow the Create a new Flutter app guide in the Flutter Docs. This will guide you step-by-step on how to create a Flutter app in your preferred development environment.
-
Add
clerk_flutterandclerk_authto your Flutter app.Terminal flutter pub add clerk_flutter clerk_auth -
The Clerk packages can now be imported into your Flutter app.
Configure the AndroidManifest.xml file
This step is only necessary if you want to run your Flutter app on Android devices. If you won't release an Android build of your Flutter app, skip this section.
In android/app/src/main/AndroidManifest.xml, inside the root <manifest> tag, add the following line to enable internet permission when running your Flutter app on Android.
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
...
</manifest>Wire up ClerkAuth
ClerkAuth is the root control widget that initializes the Clerk authentication system. Wrap your MaterialApp with it and pass your publishable key via ClerkAuthConfig.
The following example demonstrates how to wrap your MaterialApp with ClerkAuth and use ClerkAuthBuilder to render different content depending on whether a user is signed in or out. ClerkAuthentication is passed as the signedOutBuilder to display Clerk's prebuilt sign-in and sign-up UI.
import 'package:clerk_flutter/clerk_flutter.dart';
import 'package:flutter/material.dart';
void main() {
runApp(
ClerkAuth(
config: ClerkAuthConfig(publishableKey: 'YOUR_PUBLISHABLE_KEY'),
child: MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('My App')),
body: SafeArea(
child: ClerkErrorListener(
child: Padding(
padding: const EdgeInsets.all(16),
child: ClerkAuthBuilder(
signedInBuilder: (context, authState) {
return const Center(child: Text('You are signed in!'));
},
signedOutBuilder: (context, authState) {
return const ClerkAuthentication();
},
),
),
),
),
),
),
),
);
}Run your application
Now run your Flutter app.
Create your first user
Once the app launches successfully, the ClerkAuth widget opens, allowing you to sign up or sign in to create your first user.
Next steps
Learn more about Clerk widgets, how to customize them, and explore the Clerk Flutter SDK using the following guides.
Prebuilt widgets
Customize Clerk
ClerkThemeExtension.