Skip to content

Instantly share code, notes, and snippets.

@blaugold
Last active November 21, 2021 18:20
Show Gist options
  • Save blaugold/e7d05574161e64055639683c013e017f to your computer and use it in GitHub Desktop.
Save blaugold/e7d05574161e64055639683c013e017f to your computer and use it in GitHub Desktop.
Future<MutableDocument> createNote({
required String title,
required String body,
}) async {
// In Couchbase Lite, data is stored in JSON like documents. The default
// constructor of MutableDocument creates a new document with a randomly
// generated id.
final doc = MutableDocument({
// Since documents of different types are all stored in the same database,
// it is customary to store the type of the document in the `type` field.
'type': 'note',
'title': title,
'body': body,
});
// Now save the new note in the database.
await database.saveDocument(doc);
return doc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment