The SDK in Flutter
Flutter apps use the SDK through its plugin, squiddy_flutter, on Android, iOS and the web, with one Dart API: options with defaults, durations as Duration, values to read now or to listen to as a Stream, and errors that are Dart exceptions. The plugin is a thin bridge: on Android it runs the SDK's Android library, on iOS its Swift package, in a browser its npm package, all of the plugin's own version, so a Flutter app has the same stored configuration, conditional checks, backoff, gate and languages as a native one. What the SDK does, what the API key allows and how the SDK behaves offline are on the SDK page; this page is the integration.
Install
In the app's pubspec.yaml:
dependencies:
squiddy_flutter: ^0.9.0
or flutter pub add squiddy_flutter. The plugin is on pub.dev, at version 0.9.0, the same release as on the other platforms: in a 0.x version a minor version may change the API, so ^0.9.0 takes the fixes of 0.9 and not 0.10.
| Android | iOS | Web | |
|---|---|---|---|
| Minimum | API 24; the app compiles against API 37 | iOS 15, through Swift Package Manager | a browser with ES modules and import maps |
| What the plugin runs | cloud.squiddy:squiddy-android, from Maven Central | the Swift package squiddy-cloud/squiddy-swift | the npm package @squiddy-cloud/sdk, which the page loads |
app_type sent to Squiddy | android | ios | web |
| Bundle id | the application id | the main bundle's identifier | the page's host name |
| Storage | the app's no-backup files directory | Library/Application Support/squiddy, excluded from backups | the page's localStorage |
| Push update | yes | yes | no |
Flutter 3.50.1 or later, with Dart 3.14. What each platform asks of the app:
- Android:
compileSdk = 37inandroid/app/build.gradle.kts, above Flutter's default, because the SDK's library requires it of every app that uses it (itsminSdkandtargetSdkare not affected). - iOS: Swift Package Manager, which Flutter uses by default for iOS plugins. CocoaPods is not supported: an app that turned Swift Package Manager off in Flutter turns it back on (
flutter config --enable-swift-package-manager). The deployment target is iOS 15 or later. - Web: the page loads the SDK's npm package, at the plugin's version, through an import map in
web/index.html(see the web).
Keep the key out of the repository
The key ends up inside the app, so it is not a secret (see the API key), but like any credential it does not belong in the repository. One way: a JSON file that git ignores, which Flutter compiles into the app with --dart-define-from-file, and String.fromEnvironment to read it.
{ "SQUIDDY_API_KEY": "sqd_…" }
That is squiddy.local.json, never committed;
const apiKey = String.fromEnvironment('SQUIDDY_API_KEY');
flutter run --dart-define-from-file=squiddy.local.json
A pipeline writes the same file from a secret variable before it builds.
Initialize
Create one instance per app and Squiddy environment, when the app starts, and keep it: there is no global instance and no automatic start.
import 'package:squiddy_flutter/squiddy_flutter.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final squiddy = await Squiddy.initialize(const SquiddyOptions(
host: 'https://squiddy.example.com',
apiKey: String.fromEnvironment('SQUIDDY_API_KEY'),
appId: 'my-app',
appVersion: '2026.11.28', // YYYY.MM.DD: Squiddy compares it as a number
appMode: kReleaseMode ? 'release' : 'debug',
));
runApp(MyApp(squiddy: squiddy));
}
Squiddy.initialize hands the options to the SDK, which checks every one before it starts, and returns at once, without waiting for the disk or the network: config is pending until the stored configuration is read. Options the SDK refuses throw a SquiddyInitializationException, whose error is invalidOptions (a missing or empty option, a version that is not YYYY.MM.DD, a host that is not an http or https URL) or storageUnavailable (the device gave no place for the files), and whose message names the option to fix. close() stops the updates and ends the streams.
Options
Only the first five are required.
| Option | Default | What it does |
|---|---|---|
host, apiKey, appId, appVersion, appMode | — | Required. appVersion is YYYY.MM.DD; appMode is matched against the configuration's modes, such as debug and release |
customParams | none | The custom parameters the configuration's rules match, sent as given |
bundleId | the platform's (see Install) | Another identifier, sent as given |
language | the device's, or the browser's | A language of the app's own, sent as given; setLanguage changes it later |
entityId | the installation id | An opaque id of yours that rollouts place the user by (see rollouts) |
timeout | 10 seconds | The longest one call may take |
pushRefreshJitter | up to 1 minute | The longest random wait before the check a push update asks for, so the installations do not call at the same instant; not used on the web |
logger | none | A function (level, message, cause): debug lines show the HTTP headers with the key redacted, warning lines the problems the SDK recovered from |
How often the SDK checks while the app stays in the foreground is not an option: the configuration decides it with the refreshInterval of its API block, and by default there is no periodic check (the periodic check).
The configuration
config, gate and strings are SquiddyObservables: each has its value now, and is a Stream that starts with that value and then delivers every change; the subscription is what stops it. A check that finds the configuration unchanged delivers nothing.
StreamBuilder<SquiddyState>(
stream: squiddy.config,
initialData: squiddy.config.value,
builder: (context, snapshot) {
final timeout = snapshot.requireData.configuration?.serverApi?.setting('timeout')?.asInt();
return Text('Timeout: ${timeout ?? 30}');
},
);
A state has a kind: pending, ready or failed. A ready state has its origin, cache from the device's storage or network once Squiddy sent or confirmed it; a failed one has its error and the configuration still served. A configuration has its version, its serverApi (baseUrl, mode, apiVersion, isDebugActive and settings, with setting(key)), its two notices appUpdate and infoPoint, and its strings. A setting reads as text with value, or with asInt(), asDouble() and asBoolean(), which throw a SettingTypeException naming the setting when the value is not of that type. The values compare with ==, so a widget rebuilt with an equal one changes nothing.
The gate
gate says which screen the app shows:
StreamBuilder<AppGate>(
stream: squiddy.gate,
initialData: squiddy.gate.value,
builder: (context, snapshot) => switch (snapshot.requireData.kind) {
AppGateKind.none => const HomeScreen(),
AppGateKind.updateRequired => UpdateScreen(snapshot.requireData),
AppGateKind.maintenance => MaintenanceScreen(snapshot.requireData),
},
);
updateRequired comes from an app-update notice marked as required for this version, maintenance from an info-point notice that halts the app, and when both apply maintenance wins. Titles and messages arrive already localized by Squiddy; a title or a message left blank for the language arrives empty, and the gate applies all the same. The gate holds for the configuration read from the device too, so a maintenance stays on screen offline, and it is none while there is no configuration at all. The notices stay readable one by one, with their flags, in configuration.appUpdate (isRequired) and configuration.infoPoint (isHalting).
The enums are closed sets, like the SDK's types on the other platforms: until 1.0.0 a minor version may add a member, and says so in the changelog, which makes a switch without a default branch stop compiling until it handles it.
Strings
final title = squiddy.string('welcome_title', fallback: 'Welcome');
string reads the strings the SDK delivered last, at once, so it serves in a build method. A string is looked up in the language the SDK asks in, then in the configuration's default language, then the fallback (null without one), and only a key the language does not have goes on to the next. An empty text is a text: a translation left blank in the dashboard is returned empty, with or without the fallback, so a key left blank in a language stays blank in the app. strings is the value of all of them, for a widget that rebuilds when they change. The configuration holds every language its API block supports, so a change of language changes the strings at once, without a call.
Language
The SDK asks Squiddy in the device's language (the browser's on the web), and follows it while the app runs. An app with its own language picker calls await squiddy.setLanguage('en'), and setLanguage(null) goes back to the device's; a blank language throws a SquiddyLanguageException (invalidLanguage). When the language changes, the strings switch at once, and the SDK checks with Squiddy, in the foreground, for the texts of the notices, which Squiddy localizes for each call.
When the SDK checks
As on the native platforms: at every start, after serving the stored configuration; whenever the app comes back to the foreground (a page: whenever it becomes visible again); and, if the API block of the configuration has a refreshInterval, at that interval while it stays there (the periodic check). In the background it makes no call. await squiddy.refresh() asks for a check now, and the outcome arrives in config.
The web
In a browser the plugin runs the SDK's npm package, @squiddy-cloud/sdk, at the plugin's version: the package is not a Dart package, so the page loads it. The plugin imports it by its name at the first Squiddy.initialize, and the app's web/index.html maps that name to the package's module in an import map, before Flutter starts:
<script type="importmap">
{ "imports": { "@squiddy-cloud/sdk": "./squiddy/squiddy.mjs" } }
</script>
<script src="flutter_bootstrap.js" async></script>
Here the package's files are in web/squiddy, which flutter build web copies into the site with the rest of web/. To get them, at the version of the plugin:
npm pack @squiddy-cloud/sdk@0.9.0
mkdir -p web/squiddy && tar -xzf squiddy-cloud-sdk-0.9.0.tgz -C web/squiddy --strip-components=1
npm pack downloads the package and checks it against the registry's checksum; its dependency ws is for Node.js alone, and a page never loads it. The map may name any URL of the same files instead, a CDN or a bundler's output included, as long as it is the plugin's version: the plugin of a release relies on that release's npm package. Without the map, Squiddy.initialize throws a StateError that says what to add. The package is 23 ES modules, about 3.1 MB before compression, which the browser fetches together: serve them with an HTTP server that accepts many connections at once (python3 -m http.server, whose queue holds only a few, sometimes resets some of them on the first load).
What else is different in a page, as in the SDK on the web:
- the configuration and the installation id are in the origin's
localStorage, and a page checks whenever it becomes visible again; - the data plane answers the browser's CORS checks for every origin, so the page may be served from anywhere;
- there is no push update:
handlePushreturnsfalseand does nothing, so the same Firebase handler serves every platform, andpushTopicthrows anUnsupportedError, so the subscription stays behind theif (!kIsWeb)the app already needs for Firebase's topics;pushRefreshJitteris not used.
Push update
Push update is a button on each configuration in the dashboard: Squiddy sends a data-only message of Firebase Cloud Messaging to the configuration's topic, and every installation subscribed to it checks within a random wait of up to pushRefreshJitter. The plugin does not depend on Firebase: the app subscribes to the topic the SDK gives it, with firebase_messaging, and hands the messages it receives to the SDK.
What it takes is what the native apps need, for each platform the app runs on: a Firebase project with the app's Android and Apple apps, on iOS the Push Notifications capability, the Remote notifications background mode and an APNs key uploaded to Firebase (see the push update on Android and iOS), and the project's service account key uploaded to the configuration's Push update tab in the dashboard. Then, after Firebase.initializeApp:
import 'package:firebase_messaging/firebase_messaging.dart';
if (!kIsWeb) {
final messaging = FirebaseMessaging.instance;
await messaging.subscribeToTopic(squiddy.pushTopic);
FirebaseMessaging.onMessage.listen(
(message) => squiddy.handlePush(message.data.map((key, value) => MapEntry(key, '$value'))),
);
}
handlePush returns true for Squiddy's message, whose data says squiddy = refresh and names its topic in squiddy_topic, and false for any other, which stays the app's. On iOS, Firebase refuses a subscription until it has the device's APNs token: wait for messaging.getAPNSToken() to be other than null before subscribing.
While the app runs. FirebaseMessaging.onMessage delivers the messages that arrive while the app is in the foreground. A message that arrives in the background goes to the background handler of firebase_messaging, which runs in an isolate of its own, without the app's instance of the SDK: hand it nothing there, and the SDK checks anyway when the app comes back to the foreground. A native app, whose SDK lives in the app's process, also checks in the background; in a Flutter app the push update reaches the installations in the foreground, and the others at their next return.
The topic is squiddy- and 64 hexadecimal digits, computed from the API key and the appId: every installation that reads the same configuration with the same key shares it. A version of the app with another key has another topic: keep the topic you subscribed to and, when pushTopic differs, unsubscribe from the old one.
Errors
A failed check is a failed state whose error has a kind, a message, retryAfterSeconds (for rateLimited, when Squiddy said how long) and exceptionCode (for serverError, when Squiddy sent one). The table of errors says what each one means:
SquiddyErrorKind | Error in the table |
|---|---|
unauthenticated | Unauthenticated |
appNotPublished | AppNotPublished |
incompleteConfiguration | IncompleteConfiguration |
invalidRequest | InvalidRequest |
tenantSuspended | TenantSuspended |
rateLimited | RateLimited |
serverError | ServerError |
network | Network, and on the web any answer the browser does not let the page read |
timeout | Timeout |
malformedResponse | MalformedResponse |
final error = squiddy.config.value.error;
if (error?.kind == SquiddyErrorKind.tenantSuspended) tellSomeone();
No other exception leaves the plugin, except SquiddyInitializationException from initialize, SquiddyLanguageException from setLanguage, and, on the web, the StateError of a page without the import map and the UnsupportedError of pushTopic.
The sample
The SDK's repository has a Flutter sample, on Android, iOS and the web, with the screen of the other samples: the state of the configuration with a button that checks now, the gate, a localized string, a language picker, the configuration's settings, and the push update with firebase_messaging. It reads the configuration squiddy-sample, with the key in a squiddy.local.json that git ignores and --dart-define-from-file, and its web/index.html maps the npm package as above.