buildListView method
Widget
buildListView(
- BuildContext context,
- AsyncSnapshot<
List> asyncSnapshot, - PaginationController controller
Implementation
Widget buildListView(
BuildContext context,
AsyncSnapshot<List<dynamic>> asyncSnapshot,
PaginationController controller) {
if (!asyncSnapshot.hasData) {
return bottomLoader ?? const SizedBox.shrink();
}
controller.items.addAll(asyncSnapshot.data!.toSet());
if (!isGridView) {
return ListView.builder(
scrollDirection: axis,
shrinkWrap: true,
primary: false,
itemCount: controller.items.length + 1,
itemBuilder: (context, index) => (index == controller.items.length &&
(!controller.isCompleted && controller.items.length >= 10))
? bottomLoader ?? const SizedBox.shrink()
: (index == controller.items.length &&
(!controller.isCompleted &&
controller.items.length < 10 &&
controller.items.isNotEmpty))
? const SizedBox.shrink()
: (index == controller.items.length &&
controller.items.isEmpty &&
!controller.busy)
? emptyWidget ?? const SizedBox.shrink()
: (index == controller.items.length &&
controller.items.isEmpty &&
controller.busy)
? bottomLoader ?? const SizedBox.shrink()
: (index == controller.items.length &&
controller.isCompleted)
? SizedBox(
height: MediaQuery.of(context).size.height / 15,
)
: itemBuilder(
context, controller.items[index], index),
);
} else {
return GridView.builder(
scrollDirection: axis,
shrinkWrap: true,
primary: false,
itemCount: controller.items.length + 1,
// crossAxisSpacing: 5,
// mainAxisSpacing: 5,
// crossAxisCount: 2,
gridDelegate: gridDelegate ??
const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 5,
crossAxisSpacing: 5.0,
mainAxisSpacing: 5.0,
),
itemBuilder: (BuildContext context, int index) => (index ==
controller.items.length &&
!controller.isCompleted)
? bottomLoader ?? const SizedBox.shrink()
: (index == controller.items.length && controller.items.isEmpty)
? emptyWidget ?? const SizedBox.shrink()
: (index == controller.items.length && controller.isCompleted)
? SizedBox(
height: MediaQuery.of(context).size.height / 15,
)
: itemBuilder(context, controller.items[index], index),
);
}
}