Skip to main content

appwrite 28.2.0 copy "appwrite: ^28.2.0" to clipboard
appwrite: ^28.2.0 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
0
points
16.2k
downloads

Documentation

Documentation

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

unknown (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