mirror of
https://github.com/appwrite/sdk-for-flutter.git
synced 2026-06-06 19:37:52 +00:00
34 lines
913 B
Markdown
34 lines
913 B
Markdown
```dart
|
|
import 'package:appwrite/appwrite.dart';
|
|
|
|
Client client = Client()
|
|
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
|
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
|
|
|
Avatars avatars = Avatars(client);
|
|
|
|
// Downloading file
|
|
Uint8List bytes = await avatars.getImage(
|
|
url: 'https://example.com',
|
|
width: 0, // optional
|
|
height: 0, // optional
|
|
)
|
|
|
|
final file = File('path_to_file/filename.ext');
|
|
file.writeAsBytesSync(bytes);
|
|
|
|
// Displaying image preview
|
|
FutureBuilder(
|
|
future: avatars.getImage(
|
|
url:'https://example.com' ,
|
|
width:0 , // optional
|
|
height:0 , // optional
|
|
), // Works for both public file and private file, for private files you need to be logged in
|
|
builder: (context, snapshot) {
|
|
return snapshot.hasData && snapshot.data != null
|
|
? Image.memory(snapshot.data)
|
|
: CircularProgressIndicator();
|
|
}
|
|
);
|
|
```
|