cbl_flutter 1.0.0+0 copy "cbl_flutter: ^1.0.0+0" to clipboard
cbl_flutter: ^1.0.0+0 copied to clipboard

outdated

Flutter Plugin for Couchbase Lite, an embedded, NoSQL JSON Document Style database, supporting Blobs, Encryption, N1QL Queries, Live Queries, Full-Text Search and Data Sync.

Version License CI codecov

Couchbase Lite is an embedded, NoSQL JSON Document Style database, supporting Blobs, Encryption, N1QL Queries, Live Queries, Full-Text Search and Data Sync.

It can be used as a standalone embedded database for mobile or desktop apps. Or it can be combined with [Sync Gateway] to synchronize with a central data store.


What are all these packages for?

Couchbase Lite can be used with standalone Dart or with Flutter apps and comes in two editions: Community and Enterprise.

Regardless of the app platform and edition of Couchbase Lite you use, you always need the cbl package. All of the APIs of Couchbase Lite live in this package.

What other packages you need depends on the app platform and the edition of Couchbase Lite you use.

Package Required when you want to: Pub Likes Points Popularity
cbl use Couchbase Lite.
cbl_dart use the Community or Enterprise Edition in a standalone Dart app or in Flutter unit tests.
cbl_flutter use Couchbase Lite in a Flutter app.
cbl_flutter_ce use the Community Edition in a Flutter app.
cbl_flutter_ee use the Enterprise Edition in a Flutter app.
cbl_sentry integrate Couchbase Lite with Sentry in a Dart or Flutter app.

๐ŸŽฏ Platform Support #

Platform Version
iOS >= 10.0
macOS >= 10.14
Android >= 22
Linux * == Ubuntu 20.04-x86_64
Windows >= 10

*: ๐Ÿ› Currently broken because of a bug in Flutter. Most notably, operations trying to return an error crash the app.

๐Ÿ”Œ Getting started #

  1. Add cbl and cbl_flutter as dependencies:

    dependencies:
      cbl: ...
      cbl_flutter: ...
    
  2. Select the edition of Couchbase Lite you want to use, by adding as a dependency either cbl_flutter_ce for the Community Edition or cbl_flutter_ee for the Enterprise Edition:

    # This dependency selects the Couchbase Lite Community Edition.
    cbl_flutter_ce: ...
    

    โš–๏ธ You need to comply with the Couchbase licensing terms of the edition of Couchbase Lite you select.

  3. Make sure you have set the required minimum target version in the build systems of the platforms you support.

  4. Initialize Couchbase Lite before using it:

    import 'dart:io';
    
    import 'package:cbl_flutter/cbl_flutter.dart';
    import 'package:cbl_flutter_ce/cbl_flutter_ce.dart';
    
    Future<void> initCouchbaseLite() async {
      await CouchbaseLiteFlutter.init();
    }
    

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.

๐Ÿงช Flutter unit tests #

Flutter unit tests are executed by a headless version of Flutter, on the development host.

You can use the cbl package in your unit tests, but you need to use cbl_dart to initialize Couchbase Lite, instead of cbl_flutter:

import 'dart:io';

import 'package:cbl/cbl.dart';
import 'package:cbl_dart/cbl_dart.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  setUpAll(() async {
    // If no `filesDir` is specified when initializing CouchbaseLiteDart, the
    // working directory is used as the default database directory.
    // By specifying a `filesDir` here, we can ensure that the tests don't
    // create databases in the project directory.
    final tempFilesDir = await Directory.systemTemp.createTemp();
    await CouchbaseLiteDart.init(edition: Edition.community, filesDir: tempFilesDir.path);
  });

  test('use a database', () async {
    final db = await Database.openAsync('test');
    await db.saveDocument(MutableDocument({'message': 'Hello, World!'}));
    await db.close();
  });
}

Unit tests are the best way to learn, experiment and validate ideas, since they launch much quicker than integration tests. Be aware though, that using Couchbase Lite like this cannot replace integration testing your database code on actual devices or even simulators.

These tests can validate that you're using Couchbase Lite correctly and the code works as expected generally, but subtle differences between platforms, operating system versions and devices can still crop up.

๐Ÿ’ก Where to go next #

  • Check out the example app in the Example tab.
  • Look at the usage examples for cbl.

โš–๏ธ Disclaimer #

โš ๏ธ This is not an official Couchbase product.

44
likes
0
pub points
88%
popularity

Publisher

verified publishercbl-dart.dev

Flutter Plugin for Couchbase Lite, an embedded, NoSQL JSON Document Style database, supporting Blobs, Encryption, N1QL Queries, Live Queries, Full-Text Search and Data Sync.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

cbl, cbl_flutter_platform_interface, flutter, path_provider

More

Packages that depend on cbl_flutter