cbl_flutter 1.0.0-beta.6 cbl_flutter: ^1.0.0-beta.6 copied to clipboard
Couchbase Lite for Flutter. Couchbase Lite is A NoSQL database with change notification, full text search and replication.
cbl_flutter #
Flutter plugin for Couchbase Lite (cbl
).
Supported Platforms #
Platform | Version |
---|---|
iOS | >= 11 |
macOS | >= 10.15 |
Android | >= 22 |
Linux | == Ubuntu 20.04 x86_64 |
⚡ Linux is currently broken because of a bug in the Flutter. Most notably, operations trying to return an error crash the app.
Getting started #
- You need to add
cbl
andcbl_flutter
and as dependencies:
dependencies:
cbl: ^1.0.0-beta.6
cbl_flutter: ^1.0.0-beta.6
- Select the edition of Couchbase Lite you want to use, by adding as a
dependency either
cbl_flutter_ce
for the Community Edition orcbl_flutter_ee
for the Enterprise Edition:
# This dependency selects the Couchbase Lite Community Edition.
cbl_flutter_ce: ^1.0.0-beta.0
⚠️ You need to comply with the Couchbase licensing terms of the edition of Couchbase Lite you select.
-
Make sure you have set the required minimum target version in the build systems of the platforms you support.
-
Couchbase Lite needs to be initialized, before it can be used:
import 'dart:io';
import 'package:cbl_flutter/cbl_flutter.dart';
import 'package:cbl_flutter_ce/cbl_flutter_ce.dart';
Future<void> initCouchbaseLite() async {
// On mobile platforms, `CblFlutterCe` and `CblFlutterEe` currently need to
// be registered manually. This is due to a temporary limitation in how Flutter
// initializes plugins, and will become obsolete eventually.
if (Platform.isIOS || Platform.isAndroid) {
CblFlutterCe.registerWith();
}
await CouchbaseLiteFlutter.init();
}
- Now you can start using Couchbase Lite, for example by opening a database:
import 'package:cbl/cbl.dart';
Future<void> useCouchbaseLite() async {
final db = await Database.openAsync('chat-messages');
final doc = MutableDocument({
'type': 'message',
'body': 'Heyo',
'from': 'Alice',
});
await db.saveDocument(doc);
await db.close();
}
Default database directory #
When opening a database without specifying a directory,
path_provider
's getApplicationSupportDirectory
is used to
resolve it. See that function's documentation for the concrete locations on the
various platforms.