|
| 1 | +--- |
| 2 | +title: '`ClerkAuthentication`' |
| 3 | +description: Clerk's ClerkAuthentication widget renders a UI for signing in and signing up users in your Flutter app. |
| 4 | +sdk: flutter |
| 5 | +--- |
| 6 | + |
| 7 | +[//]: # ({{ style: { maxWidth: '460px' } }}) |
| 8 | + |
| 9 | +The `ClerkAuthentication` widget renders a comprehensive authentication interface with support for multiple sign-up flows and sign-in methods, multi-factor authentication, password reset, and account recovery. The functionality of the `ClerkAuthentication` widget is controlled by the instance settings you specify in the [Clerk Dashboard](https://dashboard.clerk.com), such as [sign-in and sign-up options](/docs/guides/configure/auth-strategies/sign-up-sign-in-options) and [social connections](/docs/guides/configure/auth-strategies/social-connections/overview). |
| 10 | + |
| 11 | +By default, `ClerkAuthentication` automatically determines whether to sign users in or sign them up based on whether they already have an account, providing a seamless authentication experience without requiring users to choose between the two flows. |
| 12 | + |
| 13 | +`ClerkAuthentication` must be placed somewhere below a [`ClerkAuth`](/docs/flutter/getting-started/clerk-auth) widget in the widget tree. |
| 14 | + |
| 15 | +## Parameters |
| 16 | + |
| 17 | +`ClerkAuthentication` has no additional parameters beyond the standard Flutter `key`. |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +### Basic usage |
| 22 | + |
| 23 | +The following example shows how to embed `ClerkAuthentication` in a screen that conditionally shows the authentication widget or the signed-in content. |
| 24 | + |
| 25 | +```dart |
| 26 | +import 'package:clerk_flutter/clerk_flutter.dart'; |
| 27 | +import 'package:flutter/material.dart'; |
| 28 | +
|
| 29 | +class HomeScreen extends StatelessWidget { |
| 30 | + const HomeScreen({super.key}); |
| 31 | +
|
| 32 | + @override |
| 33 | + Widget build(BuildContext context) { |
| 34 | + final user = ClerkAuth.userOf(context); |
| 35 | +
|
| 36 | + if (user != null) { |
| 37 | + return const Text('You are signed in!'); |
| 38 | + } |
| 39 | +
|
| 40 | + return const ClerkAuthentication(); |
| 41 | + } |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +### Present as a modal sheet |
| 46 | + |
| 47 | +The following example shows how to present `ClerkAuthentication` as a modal bottom sheet when the user taps a button. |
| 48 | + |
| 49 | +```dart |
| 50 | +import 'package:clerk_flutter/clerk_flutter.dart'; |
| 51 | +import 'package:flutter/material.dart'; |
| 52 | +
|
| 53 | +class HomeScreen extends StatelessWidget { |
| 54 | + const HomeScreen({super.key}); |
| 55 | +
|
| 56 | + @override |
| 57 | + Widget build(BuildContext context) { |
| 58 | + return Scaffold( |
| 59 | + body: Center( |
| 60 | + child: ElevatedButton( |
| 61 | + onPressed: () { |
| 62 | + showModalBottomSheet<void>( |
| 63 | + context: context, |
| 64 | + isScrollControlled: true, |
| 65 | + builder: (_) => const ClerkAuthentication(), |
| 66 | + ); |
| 67 | + }, |
| 68 | + child: const Text('Sign in'), |
| 69 | + ), |
| 70 | + ), |
| 71 | + ); |
| 72 | + } |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +## Customization |
| 77 | + |
| 78 | +<Include src="_partials/views/customization" /> |
0 commit comments