> ## Documentation Index
> Fetch the complete documentation index at: https://docs.clariodesk.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Flutter lifecycle

> The four host events that touch the SDK: wire each one and you're done.

Four host events interact with the SDK. The concepts are the same across both
SDKs ([read the shared overview](/concepts/identity-lifecycle)); this page gives
the exact Flutter code.

## 1. App launch (every time, including already-logged-in users)

The most common miss: existing users who installed your app before you added
ClarioDesk never hit the login flow again. Hydrate from your own session on
launch and identify **unconditionally**. `identify()` is idempotent and cheap.

```dart theme={null}
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await ClarioDesk.init(apiKey: 'pk_live_…');

  final user = await yourAuth.currentUser(); // Firebase, Supabase, your store…
  if (user != null) {
    await ClarioDesk.identify(
      externalId: user.id,
      email: user.email,
      traits: {'plan': user.plan},
    );
  }

  runApp(const MyApp());
}
```

## 2. Fresh login or signup

Right after your auth succeeds:

```dart theme={null}
await yourAuth.signIn(email, password);
await ClarioDesk.identify(
  externalId: user.id,
  email: user.email,
  traits: {'plan': user.plan},
);
```

This overwrites the label on the existing device row. The same device and
hardware key are reused; nothing new is registered.

## 3. Logout

```dart theme={null}
await ClarioDesk.clearIdentity(); // Verified identity
await yourAuth.signOut();
```

This preserves the device key while changing the signed identity epoch. In
label-only mode, `reset()` is still available for full installation isolation.

## 4. User switch (A → B without app restart)

```dart theme={null}
await ClarioDesk.clearIdentity();
await yourAuth.switchTo(userB);
await ClarioDesk.identify(identityMode: IdentityMode.host);
```

<Warning>
  Await clear before activating user B. `reset()` deprovisions this installation;
  it is not logout or customer erase.
</Warning>

## What if I never call `identify()`?

Tickets still work; agents see a device id but no email, and the dashboard shows
an "Unverified device" badge. This is fine for anonymous feedback; otherwise,
wire case 1.
