Rank 1: Thread
I am trying to read and write data in appwrite for my expense manager app ,since this is my first time using a database i am unable to get it right.
i have written these two functions :-
try { final document = await databases.createDocument( databaseId: constants.database_ID, collectionId: constants.collection_ID, documentId: ID.unique(), data: {'Reason': reason, 'Date': DateTime.now(),'Amount': amount,}, permissions: [ Permission.read(Role.any()), Permission.write(Role.any()), ], ); } on AppwriteException catch (e) { print(e); } }```
and
``` Future<List<Document>> getData() async { final Future<DocumentList> result = databases.listDocuments( databaseId: constants.database_ID, collectionId: constants.collection_ID, ); result.then((result) { return result.data.documents; }).catchError((error) { print(error.response); }); return []; }```
and from another class i am calling getdata as
//Function to map data from document of Appwrite``` void fetchData() async { try { final List<dynamic> data = await AuthState().getData();
setState(() { // Convert the fetched data into Expense objects and update the expenses list expenses = data.map((item) { return expense( amount: item['amount'], date: item['date'], type: item['type'], ); }).toList(); }); } catch (e) { print('Failed to fetch expenses: $e'); } }```but i am getting an error stating that the list that iam trying to print is of 0 length