Skip to main content

appwrite 28.3.0-rc.1 copy "appwrite: ^28.3.0-rc.1" to clipboard
appwrite: ^28.3.0-rc.1 copied to clipboard

Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API

example/README.md

Examples #

Initialize the client:

import 'package:appwrite/appwrite.dart';
import 'package:appwrite/models.dart' as models;

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
    .setProject('<YOUR_PROJECT_ID>');

Create a user and sign in:

Account account = Account(client);

models.User user = await account.create(
  userId: ID.unique(),
  email: 'email@example.com',
  password: 'password',
  name: "Walter O'Brien",
);

models.Session session = await account.createEmailPasswordSession(
  email: 'email@example.com',
  password: 'password',
);

Fetch the signed-in user:

models.User profile = await account.get();

List rows:

TablesDB tablesDB = TablesDB(client);

models.RowList rows = await tablesDB.listRows(
  databaseId: '<DATABASE_ID>',
  tableId: '<TABLE_ID>',
  queries: [
    Query.equal('published', true),
    Query.limit(10),
  ],
);

Upload a file. On the web there is no file system path, so upload the picked file's bytes instead:

import 'package:flutter/foundation.dart';

Storage storage = Storage(client);

InputFile input = kIsWeb
    ? InputFile.fromBytes(bytes: pickedFile.bytes!, filename: 'image.jpg')
    : InputFile.fromPath(path: './path-to-file/image.jpg');

models.File file = await storage.createFile(
  bucketId: '<BUCKET_ID>',
  fileId: ID.unique(),
  file: input,
  permissions: [
    Permission.read(Role.any()),
  ],
);

Subscribe to realtime events:

Realtime realtime = Realtime(client);

RealtimeSubscription subscription = realtime.subscribe(['account']);

subscription.stream.listen((event) {
  print(event.payload);
});

Keep the subscription while you need events, and call subscription.close() when you stop listening, for example in your widget's dispose().

Handle errors:

try {
  models.User user = await account.get();
} on AppwriteException catch (e) {
  print('${e.code} ${e.type}: ${e.message}');
}

All examples and API features are available in the official Appwrite docs.

581
likes
130
points
16.3k
downloads

Documentation

Documentation
API reference

Publisher

verified publisherappwrite.io

Weekly Downloads

Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API

Homepage
Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

cookie_jar, device_info_plus, flutter, flutter_background_service, flutter_local_notifications, flutter_web_auth_2, http, mqtt5_client, package_info_plus, path_provider, typed_data, web, web_socket_channel

More

Packages that depend on appwrite

Packages that implement appwrite