riverpod_pagination 0.1.0
riverpod_pagination: ^0.1.0 copied to clipboard
A simple and effective pagination solution for Flutter apps using Riverpod state management.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'examples/users_example.dart';
import 'examples/posts_example.dart';
import 'examples/photos_example.dart';
void main() {
runApp(const ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Riverpod Pagination Examples',
theme: ThemeData(
primarySwatch: Colors.blue,
useMaterial3: true,
),
home: const ExamplesListScreen(),
);
}
}
class ExamplesListScreen extends StatelessWidget {
const ExamplesListScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Riverpod Pagination Examples'),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text(
'Choose an example to see riverpod_pagination in action:',
style: TextStyle(fontSize: 16),
),
const SizedBox(height: 24),
_ExampleButton(
title: 'Users List (Token Pagination)',
description: 'Demonstrates token-based pagination with a users list',
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => const UsersExampleScreen()),
),
),
const SizedBox(height: 16),
_ExampleButton(
title: 'Posts List (Offset Pagination)',
description: 'Shows offset-based pagination with posts',
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => const PostsExampleScreen()),
),
),
const SizedBox(height: 16),
_ExampleButton(
title: 'Photos Grid (Page-based)',
description: 'Grid view with page number pagination',
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => const PhotosExampleScreen()),
),
),
],
),
),
);
}
}
class _ExampleButton extends StatelessWidget {
final String title;
final String description;
final VoidCallback onTap;
const _ExampleButton({
required this.title,
required this.description,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return Card(
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Text(
description,
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 8),
Align(
alignment: Alignment.centerRight,
child: Icon(
Icons.arrow_forward_ios,
size: 16,
color: Theme.of(context).colorScheme.primary,
),
),
],
),
),
),
);
}
}