Dart SDK
Install the Dart SDK, create a client, handle errors, and find every type and method by area.
The Sovaria client for Flutter (iOS, Android, desktop, web) and plain Dart. It has the same surface as the Swift, Kotlin, TypeScript and Python clients.
#Install
flutter pub add sovaria#Create a client
Use the project URL and the anon key from the console's Connect panel. The anon key is public and safe to ship in an app. Never put the service role key in a mobile app. For a full walkthrough see Flutter quickstart.
import 'package:sovaria/sovaria.dart';
final sovaria = await Sovaria.initialize(
url: 'https://<project-ref>.sovarias.in',
anonKey: '<anon-key>',
storage: SecureStore(), // your SessionStorage; the default keeps the session in memory
);
await sovaria.auth.signInWithPassword(email: 'ada@example.com', password: 'Correct-Horse-9!');#Errors
Failed calls throw with the server's machine-readable code (for example PLAN_LIMIT_REACHED or INVALID_QUERY) and a readable message. See Troubleshooting.
try {
await sovaria.db.sql('select * from orders');
} on SovariaException catch (e) {
print('${e.code}: ${e.message}');
}#Reference by area
#Client
Sovaria
The Sovaria client for Dart and Flutter.
class Sovaria implements TransportSovaria.Sovaria
Create an instance.
Sovaria({
required String url,
required this.anonKey,
String? orgId,
String? projectId,
String? envId,
SessionStorage? storage,
this.device,
AttestationProvider? attestation,
http.Client? httpClient,
this.retries = 3,
this.retryBaseDelay = const Duration(milliseconds: 200),
this.refreshMargin = const Duration(seconds: 60),
String storageKey = "",
WebSocketConnector? webSocketConnector,
}) : baseUrlSovaria.initialize
Create the client and restore the stored session (if any).
static Future<Sovaria> initialize({
required String url,
required String anonKey,
String? orgId,
String? projectId,
String? envId,
SessionStorage? storage,
SovariaDevice? device,
AttestationProvider? attestation,
http.Client? httpClient,
})Sovaria.baseUrl
A property.
final String baseUrlSovaria.anonKey
The project's public (anon) key: used for every request while nobody is signed in.
final String anonKeySovaria.storage
A property.
final SessionStorage storageSovaria.sessionKey
A property.
final String sessionKeySovaria.device
A property.
final SovariaDevice? deviceSovaria.retries
A property.
final int retriesSovaria.retryBaseDelay
A property.
final Duration retryBaseDelaySovaria.refreshMargin
A property.
final Duration refreshMarginSovaria.api
Every Sovaria operation, generated from the shared API spec (same as TypeScript and Python).
late final GeneratedApi apiSovaria.auth
A property.
late final SovariaAuth authSovaria.db
A property.
late final SovariaDatabase dbSovaria.collections
A property.
late final SovariaCollections collectionsSovaria.files
Object storage (sovaria.files.upload('avatars', 'u1/me.png', bytes)).
late final SovariaStorage filesSovaria.functions
A property.
late final SovariaFunctions functionsSovaria.realtime
A property.
late final SovariaRealtime realtimeSovaria.push
A property.
late final SovariaPush pushSovaria.crashes
Crash reporting (Monitor › Crashes); call SovariaCrashes.install early.
late final SovariaCrashes crashesSovaria.simulate
Simulation (team members): who can do what in the live project, with nothing written.
late final SovariaSimulation simulateSovaria.attestation
Set when an AttestationProvider was given.
late final AttestationManager? attestationSovaria.offline
Offline-first for the data API, once enableOffline is called.
SovariaOffline? offlineSovaria.orgId
A property.
String? get orgIdSovaria.projectId
A property.
String? get projectIdSovaria.envId
A property.
String? get envIdSovaria.enableOffline
Turn on offline-first for the data API: writes made with no network are queued and replayed in order on reconnect; db.select/reads fall back to the last cached result.
SovariaOffline enableOffline({
OfflineStore? store,
String? namespace,
void Function(SovariaException error, Map<String, Object?> write)? onSyncError,
void Function(int count)? onSynced,
})Returns the controller.
The queue and cache are kept in files in the app's private data folder by default (FileOfflineStore), so writes made offline still sync after the app is closed and reopened. Pass store: MemoryOfflineStore() to keep them for this run only.
Sovaria.setScope
void setScope({String? orgId, String? projectId, String? envId})Sovaria.scope
String? scope(String name)Sovaria.resolveScope
Learn the org/project behind the project URL (), once.
Future<void> resolveScope()Sovaria.call
Future<dynamic> call(String method, String path, {Object? body, Map<String, Object?>? query, bool auth = true})Sovaria.request
request(method, path, body: body, query: query, auth: auth)Sovaria.request
Send one request and decode the JSON answer.
Future<dynamic> request(
String method,
String path, {
Object? body,
Map<String, Object?>? query,
bool auth = true,
Map<String, String>? headers,
Uint8List? bytes,
String? contentType,
bool rawResponse = false,
})Signs with the session (refreshed when close to expiry, and once more after a 401) or the anon key; retries transient failures with backoff.
Sovaria.sendRaw
Send a prepared request (multipart uploads) through this client's HTTP client.
Future<http.Response> sendRaw(http.BaseRequest request)Sovaria.webSocketBase
wss://… form of the base URL (realtime).
String get webSocketBaseSovaria.close
Close the HTTP client and realtime sockets.
Future<void> close()SovariaException
An error answer from Sovaria (or a client-side problem such as missing configuration).
class SovariaException implements ExceptionSovariaException.SovariaException
Create an instance.
SovariaException(this.status, this.message, {this.code = "", this.details, this.traceId})SovariaException.status
HTTP status (0 for network and configuration errors).
final int statusSovariaException.code
Machine-readable code such as PLAN_LIMIT_REACHED, PKCE_REQUIRED, APP_ATTESTATION_REQUIRED.
final String codeSovariaException.message
A property.
final String messageSovariaException.details
A property.
final Object? detailsSovariaException.traceId
A property.
final String? traceIdSovariaException.isUnauthorized
A property.
bool get isUnauthorizedSovariaException.isPlanLimit
A property.
bool get isPlanLimitSovariaException.needsAttestation
A property.
bool get needsAttestationSovariaException.SovariaException.fromResponse
Builds the error from a response body (FastAPI detail, gateway error/code).
factory SovariaException.fromResponse(int status, Object? body)SovariaException.SovariaException.config
Create an instance.
factory SovariaException.config(String message)SovariaException.toString
String toString()Transport
What the generated API needs from a client: send one request, and know the default scope.
abstract class TransportTransport.call
Send method path with an optional JSON body and query; returns the decoded JSON.
Future<dynamic> call(String method, String path, {Object? body, Map<String, Object?>? query, bool auth = true})Transport.scope
The client's default org_id / project_id / env_id, or null.
String? scope(String name)