Rank 2: Process
Here is the code I have tried
class AppwriteServices {
Databases databases = Databases(client);
Future readBooks() async {
final results = databases.listDocuments(
databaseId: '647b2d9c3517092fd026',
collectionId: '647b2dac72f880f4386d');
results.then((value) {
print(value.toMap());
}).catchError((error) {
print(error);
});
}
}
##############
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: FutureBuilder(
future: AppwriteServices().readBooks(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
List records = snapshot.data['documents'];
return ListView.builder(
itemCount: records.length,
itemBuilder: (context, int index) {
return Card(
child: ListTile(
title: Text(records[index]['firstname']),
),
);
},
);
} else {
return Center(child: CircularProgressIndicator());
}
},
),
));
}
}