# Flutter quickstart
Source: https://sovaria.in/docs/mobile-flutter

Add Sovaria to a Flutter app: install, connect, sign in, read data, and keep the session in secure storage.

> **Warning:** **Release pending:** the Flutter/Dart package is not on pub.dev yet, so the install step below won't resolve until it is. Ask for early access on [the early-access page](/early-access) and we'll share the package with your team. Every type and method: [Dart SDK](https://sovaria.in/docs/dart-reference).

1. **Install**
```bash
flutter pub add sovaria flutter_secure_storage
```
2. **Register your app** — Console › Authentication › Mobile › **Apps**: add the iOS bundle id + team id and/or the Android package name + signing certificate SHA-256, and a redirect URI such as `com.example.app://auth-callback`.
3. **Connect**
```dart
import 'package:sovaria/sovaria.dart';

final sovaria = await Sovaria.initialize(
  url: 'https://<ref>.sovarias.in',           // Project settings › API
  anonKey: 'svr_anon_…',                     // public; safe to ship in the app
  storage: SecureStore(),                    // Keychain / Keystore (see below)
  device: SovariaDevice(id: deviceId, platform: Platform.operatingSystem, name: deviceName),
);
```
4. **Keep the session in secure storage**
```dart
class SecureStore implements SessionStorage {
  final _s = const FlutterSecureStorage();
  @override Future<String?> read(String key) => _s.read(key: key);
  @override Future<void> write(String key, String value) => _s.write(key: key, value: value);
  @override Future<void> delete(String key) => _s.delete(key: key);
}
```
5. **Sign in and use data**
```dart
await sovaria.auth.signInWithPassword(email: email, password: password);

final todos = await sovaria.db.select('todos', where: {'done': false}, orderBy: 'created_at', limit: 20);
await sovaria.collections.collection('notes').add({'text': 'Hello from Flutter'});
await sovaria.files.upload('avatars', '${sovaria.auth.currentUserId}/me.png', bytes, contentType: 'image/png');

final room = sovaria.realtime.channel('room:42');
room.messages.listen((m) => print(m));
```

> **Tip:** Listen to `sovaria.auth.onAuthStateChange` to switch between your signed-in and signed-out screens. Tokens refresh on their own.

## Every operation

`sovaria.api.<module>.<method>` exposes every Sovaria operation, generated from the same description as the JavaScript, Python, Swift and Kotlin SDKs (tests check all five send identical requests): `api.push`, `api.mobile`, `api.attestation`, `api.storage`, `api.functions`…

## Crash reports

Add the `sovaria_flutter` plugin and install once at start-up. It reports Flutter framework errors, errors no zone caught, root-isolate errors and native crashes (iOS signals and Mach exceptions, Android NDK crashes, ANRs, low-memory kills), grouped into issues under Monitor › Crashes with the last 50 breadcrumbs. Native reports are written to disk while the app dies and sent on the next launch. iOS needs Swift Package Manager (`flutter config --enable-swift-package-manager`). See [Crash reporting](https://sovaria.in/docs/crash-reporting).

main.dart:
```dart
// flutter pub add sovaria_flutter
await SovariaFlutter.installCrashReporting(sovaria, release: '1.4.0+12');
runApp(const MyApp());

// App attestation from the device (App Attest / Play Integrity):
final sovaria = Sovaria(url: url, anonKey: anonKey,
    attestation: SovariaFlutterAttestation(cloudProjectNumber: 123456789, iosAppId: 'TEAMID.com.example.app'));
```

Errors are `SovariaException` with `status`, `code` (`PLAN_LIMIT_REACHED`, `PKCE_REQUIRED`, `APP_ATTESTATION_REQUIRED`…) and a plain `message`.
