SDKs

Dart SDK

Using Spectron from Dart and Flutter applications.

The Spectron client ships in the surrealdb package on pub, as a standalone import that does not depend on the database driver. It works in any Dart project and on every Flutter target (Android, iOS, web, and desktop).

Add the package to pubspec.yaml:

dependencies:
  surrealdb:
dart pub get
# or, in a Flutter project
flutter pub get

Import the Spectron entry point directly. The client is pinned to one context and talks to Spectron's REST API over HTTPS:

import 'package:surrealdb/spectron.dart';

final client = Spectron(
  endpoint: 'https://api.spectron.example',
  context: 'acme-prod',
  apiKey: 'sp-your-key',
);

Importing package:surrealdb/spectron.dart pulls in only the Spectron client, not the SurrealDB database driver.

await client.remember('I was promoted to CTO', scopes: 'user/tobie');

final hits = await client.recall("What is Tobie's role?", k: 10);

await for (final chunk in client.chatStream('Tell me a story')) {
  stdout.write(chunk.delta);
}

client.close();

scopes accepts a slash-path string or a list of paths. Register paths with spectron scopes create before first use.

The client covers the rest of the Spectron end-user surface (documents, sessions, entities, and governance) over the same REST API. See the REST API for the full contract.

Was this page helpful?