Skip to content

Instantly share code, notes, and snippets.

@muyiwexy
Last active October 18, 2022 10:19
retrieve image
import 'dart:convert';
import 'package:appwrite/appwrite.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:image_uploader/constants/app_constantants.dart';
import 'package:image_uploader/models/documentmodel.dart';
import 'package:image_uploader/models/fileurl.dart';
class AppImageProvider extends ChangeNotifier {
Client client = Client();
late Databases databases;
List<DocModel>? _items;
List<DocModel>? get docmodel => _items;
AppImageProvider() {
_initialize();
}
_initialize() {
client
.setEndpoint(Appconstants.endpoint)
.setProject(Appconstants.projectid);
databases = Databases(client, databaseId: Appconstants.dbID);
_getaccount();
}
filepicker() async {
// filepicker code goes here
createdocument();
notifyListeners();
}
_getaccount() async {
// get account code goes here
}
Future _uploadfile() async {
// _uploadfile code goes here
}
createdocument() async {
try {
var url =
'${Appconstants.endpoint}/storage/buckets/${uploadedFiles!.bucketId}/files/${uploadedFiles!.id}/preview?project=${Appconstants.projectid}';
var result = await databases.createDocument(
collectionId: Appconstants.collectionID,
documentId: uploadedFiles!.id!,
data: {
'url': url,
});
} catch (e) {
print(e);
}
}
Future displayfile() async {
var result = await databases.listDocuments(
collectionId: Appconstants.collectionID,
);
_items = result.documents
.map((docmodel) => DocModel.fromJson(docmodel.data))
.toList();
notifyListeners();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment