1
0
Fork 0
mirror of synced 2024-06-13 16:24:47 +12:00
appwrite/docs/sdks/dart/EXAMPLES.md

63 lines
1.2 KiB
Markdown
Raw Normal View History

2020-04-12 18:15:33 +12:00
# Examples
Init your Appwrite client:
```dart
2022-09-15 07:18:33 +12:00
Client client = Client();
2020-04-12 18:15:33 +12:00
2022-09-15 07:18:33 +12:00
client
.setEndpoint('https://localhost/v1') // Your Appwrite Endpoint
.setProject('5e8cf4f46b5e8') // Your project ID
.setSelfSigned() // Remove in production
;
2020-04-12 18:15:33 +12:00
```
2021-01-07 02:45:47 +13:00
Create a new user:
2020-04-12 18:15:33 +12:00
```dart
2021-01-07 02:45:47 +13:00
Users users = Users(client);
2020-04-12 18:15:33 +12:00
2022-09-15 07:18:33 +12:00
User result = await users.create(
2023-10-19 08:22:39 +13:00
userId: ID.unique(),
email: "email@example.com",
phone: "+123456789",
password: "password",
2023-10-18 01:42:29 +13:00
name: "Walter O'Brien"
2021-01-07 02:45:47 +13:00
);
2020-04-12 18:15:33 +12:00
```
Fetch user profile:
```dart
2021-01-07 02:45:47 +13:00
Users users = Users(client);
2020-04-12 18:15:33 +12:00
2022-09-15 07:18:33 +12:00
User profile = await users.get(
2021-01-07 02:45:47 +13:00
userId: '[USER_ID]',
);
2020-04-12 18:15:33 +12:00
```
Upload File:
```dart
Storage storage = Storage(client);
2022-03-04 06:45:20 +13:00
InputFile file = InputFile(path: './path-to-file/image.jpg', filename: 'image.jpg');
2020-04-12 18:15:33 +12:00
storage.createFile(
2022-03-03 20:44:38 +13:00
bucketId: '[BUCKET_ID]',
fileId: '[FILE_ID]', // use 'unique()' to automatically generate a unique ID
2020-04-12 18:15:33 +12:00
file: file,
2022-09-15 07:18:33 +12:00
permissions: [
Permission.read(Role.any()),
],
2020-04-12 18:15:33 +12:00
)
.then((response) {
print(response); // File uploaded!
})
.catchError((error) {
print(error.response);
});
```
2023-10-17 08:55:54 +13:00
All examples and API features are available at the [official Appwrite docs](https://appwrite.io/docs)