1
0
Fork 0
mirror of synced 2024-07-05 22:51:24 +12:00
appwrite/docs/sdks/flutter/EXAMPLES.md
Damodar Lohani a4f183cc62 fix examples
2022-03-03 17:45:20 +00:00

1.4 KiB

Examples

Init your Appwrite client:

  Client client = Client();

  client
      .setEndpoint('https://localhost/v1') // Your Appwrite Endpoint
      .setProject('5e8cf4f46b5e8') // Your project ID
      .setSelfSigned() // Remove in production
  ;

Create a new user and session:

Account account = Account(client);

Response user = await account.create(userId: '[USER_ID]', email: 'me@appwrite.io', password: 'password', name: 'My Name');
 
Response session = await account.createSession(email: 'me@appwrite.io', password: 'password');

Fetch user profile:

Account account = Account(client);

Response profile = await account.get();

Upload File:

Storage storage = Storage(client);

late InputFile file;

if(kIsWeb) {
    file = InputFile(file: await MultipartFile.fromFile('file', './path-to-file/image.jpg', filename: 'image.jpg'));
} else {
    file = InputFile(path: './path-to-file/image.jpg', filename: 'image.jpg');
}

storage.createFile(
    bucketId: '[BUCKET_ID]',
    fileId: '[FILE_ID]', // use 'unique()' to automatically generate a unique ID
    file: file,
    read: ['role:all'],
    write: []
)
.then((response) {
    print(response); // File uploaded!
})
.catchError((error) {
    print(error.response);
});

All examples and API features are available at the official Appwrite docs