fire_pagination 0.0.1 fire_pagination: ^0.0.1 copied to clipboard
Widget to implement pagination, works with Android and Web. Paginated ListView has two required parameters itemBuilder and service. The itemBuilder parameter builds widgets using the items/data in the [...]
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fire_pagination/fire_pagination.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: PagedListView(
itemBuilder: (item, index) {
return Row(
children: [
Text('$index'),
SizedBox(width: 20),
Text('$item'),
],
);
},
service: MyService1()));
}
}
class MyService1 extends PaginationService {
@override
Future<List> getData([lastFetched]) async {
return List<int>.generate(30, (int index) => index * index);
}
}
/// This example shows how to use [PagedListView] with [Firestore].
/// The optional parameter [lastFetched] will be the cursor to implement
/// pagination. Function [getData] fetches data from this point.
//class MyService3 extends PaginationService {
// String collection = 'someCollection';
// int pageSize = 20;
//
// @override
// Future<List> getData([dynamic lastFetched = 0]) async {
// print('service fetching');
// return await lastFetched == 0
// ? FirebaseFirestore.instance
// .collection(collection)
// .orderBy('a')
// .limit(pageSize)
// .get()
// .then((value) {
// return value.docs.toList();
// })
// : FirebaseFirestore.instance
// .collection(collection)
// .orderBy('a')
// .limit(pageSize)
// .startAfterDocument(lastFetched)
// .get()
// .then((value) {
// return value.docs.toList();
// });
// }
//}