1
0
Fork 0
mirror of synced 2024-06-01 10:29:48 +12:00
appwrite/docs/sdks/flutter-dev/EXAMPLES.md
Pratik Gupta c2ce7d0aa1
Rectified flutter-dev EXAMPLES.md
Removed phone number from account.create() function as it does not accept it.
2023-10-24 09:04:48 +05:30

64 lines
1.3 KiB
Markdown

# Examples
Init your Appwrite client:
```dart
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:
```dart
Account account = Account(client);
final user = await account.create(userId: ID.unique(), email: "email@example.com", password: "password", name: "Walter O'Brien");
final session = await account.createEmailSession(email: 'me@appwrite.io', password: 'password');
```
Fetch user profile:
```dart
Account account = Account(client);
final profile = await account.get();
```
Upload File:
```dart
Storage storage = Storage(client);
late InputFile file;
if(kIsWeb) {
file = InputFile(bytes: pickedFile.bytes, 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,
permissions: [
Permission.read(Role.any()),
],
)
.then((response) {
print(response); // File uploaded!
})
.catchError((error) {
print(error.response);
});
```
All examples and API features are available at the [official Appwrite docs](https://appwrite.io/docs)