I have graphql hooked up, and the collection in question has about 2000 documents. What I want to do is simply load in 25 at a time. If I perform the query to fetch the full list it takes 5-10 seconds, so what I need is for it to only ask for 25 at a time. I have it working so it will load up X amount of documents and display them in a list. What I cannot figure out is how to get pagination working. Ive read the docs 100 times, but I cannot make sense of it. Here is the pagination doc for ferry https://ferrygraphql.com/docs/pagination
I am fairly new to flutter and dart so any help here would be appriecited. Thank you.
This is my code. Currently this just displays the first 25 documents and nothing else.
class DisplayPartnerOrganistions extends StatefulWidget {
@override
_DisplayPartnerOrganistionsState createState() =>
_DisplayPartnerOrganistionsState();
}
class _DisplayPartnerOrganistionsState
extends State<DisplayPartnerOrganistions> {
var offset = 0;
final client = GetIt.I<Client>();
late GFetchPartnerOrganisationsReq fetchPartnerOrganisationsReq;
@override
void initState() {
super.initState();
fetchPartnerOrganisationsReq = GFetchPartnerOrganisationsReq(
(b) => b
..vars.offset = offset
..vars.limit = 25,
);
}
Widget _buildList(partners) {
return ListView.builder(
padding: const EdgeInsets.all(16.0),
itemBuilder: (context, item) {
return _buildRow(partners[item]);
});
}
Widget _buildRow(partnerOrganisation) {
return ListTile(
title: Text(partnerOrganisation.toString()),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Partner Organisations'),
),
body: Operation<GFetchPartnerOrganisationsData,
GFetchPartnerOrganisationsVars>(
client: client,
operationRequest: fetchPartnerOrganisationsReq,
builder: (context, response, error) {
if (response!.loading) {
return const Center(child: CircularProgressIndicator());
}
final partners = response.data?.partnerOrganizations;
return _buildList(partners);
}),
);
}
}
I been trying different things for about 12 hours but nothing is making any sense. Am I using the wrong widgets or something?