Welcome to the Flutter SDK Installation Guide. This document provides step-by-step instructions for installing and configuring the Ditto SDK, enabling you to sync, query, and insert data seamlessly within your existing Flutter application.
1.9.20
or later
./android/settings.gradle
org.jetbrains.kotlin.android
plugin to 1.9.20
ios/Runner/Info.plist
:android/app/src/main/AndroidManifest.xml
.android/app/src/main/AndroidManifest.xml
. Then edit the service metadata appropriately.small_app_icon
drawable must be monochrome white.The foreground service will be automatically started and stopped on startSync()
and stopSync()
, respectively.appID
, playground token
, authURL
, and websocketURL
for your application. These are required to initialize the Ditto SDK.dart:io
. However, this
prevents using Platform.is...
to detect the current platform. Note that this
is a compile-time error, so it is not possible to work around this with
kIsWeb
.To streamline this, the Ditto Flutter SDK provides Ditto.currentPlatform
,
which is usable on all platforms.Ditto
. This is the main entry point into all Ditto-related functionality.items
:
insertData
function wherever appropriate in your application, such as in a button press handler.
items
collection:
observeData
function, typically in the initState
method of a stateful widget to start observing when the widget is initialized.
dispose()
method to prevent resource leaks
startSync
. This enables this device to sync data with other peers including the Ditto Cloud.
items
collection:
syncData
function, typically when initializing your Ditto instance.
await Ditto.init()
. By default, assets are bundled with the application and loaded
from the same web server that serves the application. After running flutter build web
, you can find those in the
build/web/assets/packages/ditto_live/lib/assets
directory.
Alternatively, you can host the contents of that directory on a CDN or other web
server and configure Ditto to load assets from there. All contents of the
directory, excluding the ditto.wasm
file itself, must be reachable at the URL
given by the wasmShimUrl
parameter. The ditto.wasm
file can be served from a
separate URL given by the wasmUrl
parameter.
Configuration for loading all assets from a CDN:
v
in your terminal after
flutter run
-ing your app. Then, in the top bar of the devtools window, click
on ditto_live
(depending on the size of your browser window, it may be in a
drop-down menu). The first time you open the Ditto devtools extension, you will
need to grant it permission.
Once it’s running, it will connect to your app and communicate with the first
Ditto
instance that your app created. If no Ditto
instances have been
created, it will not load.
The extension has two text fields - one for the query, and one for the
arguments. Arguments are parsed as JSON5, which is compatible with JSON, but
has some ergonomic improvements, such as:
--dart-define
and const String.fromEnvironment
. See this
page for
more details.appFlavor
global. See this
page for more details.kDebugMode
, kReleaseMode
, etc.