realtime_pagination 0.0.8 copy "realtime_pagination: ^0.0.8" to clipboard
realtime_pagination: ^0.0.8 copied to clipboard

A Flutter package that helps use realtime pagination with Firestore

example/lib/main.dart

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:realtime_pagination/realtime_pagination.dart';

import 'models/post.dart';
import 'widgets/post_widget.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(App());
}

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primaryColor: Colors.green,
      ),
      home: Home(),
    );
  }
}

class Home extends StatelessWidget {
  const Home({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('Realtime Pagination'),
      ),
      body: RealtimePagination(
        query: _postsQuery(),
        itemsPerPage: 15,
        itemBuilder: (index, context, docSnapshot) {
          final post = Post.fromMap(docSnapshot.data());
          return PostWidget(post);
        },

        // CUSTOM BUILDER HERE
        customPaginatedBuilder: (itemCount, controller, itemBuilder) {
          // ASSIGN THESE THREE PROPERTIES, CUSTOMIZE THE REST AS YOU WANT!
          return ListView.builder(
            controller: controller, // 1
            itemCount: itemCount, // 2
            itemBuilder: itemBuilder, // 3
          );
        },
      ),
    );
  }

  Query _postsQuery() {
    return FirebaseFirestore.instance
        .collection('posts')
        .orderBy('createdAt', descending: true);
  }
}
16
likes
120
pub points
22%
popularity

Publisher

unverified uploader

A Flutter package that helps use realtime pagination with Firestore

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

bloc, cloud_firestore, flutter

More

Packages that depend on realtime_pagination