搜索插件、代码仓与 APP 分类

pager 封面
插件详情v0.0.6

pager

一个可用于构建数字分页的组件,例如,如果您想构建自定义分页表格时非常有用。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
494
喜欢数
26
Pub 分数
160

安装插件

flutter pub add pager

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Pager 是一个 Flutter 小部件,旨在创建可自定义的数字分页界面,非常适合实现分页显示,例如自定义分页表格。它提供了一种简洁、可重用的方式,通过直观的控件在页面间导航,并支持多种样式选项。该组件以简单性和灵活性为核心设计,可无缝集成到面向多平台的应用程序中。

适合场景

  • 自定义分页表格实现
  • 在列表中导航大型数据集
  • 构建用户友好的页面导航
  • 创建响应式数据网格
  • 使用离散页面实现无限滚动
  • 在数据密集型应用中提升用户体验

主要特点

  • 数值页指示器
  • 可配置的页面范围显示
  • 支持向前和向后导航
  • 与 ListView 或 DataTable 的轻松集成
  • 通过主题或属性进行自定义样式
  • 跨平台兼容性

适合对象

  • 开发数据密集型 UI 的开发者
  • 需要轻量级分页的团队
  • 需要自定义表格分页的应用
  • Flutter 项目针对多个平台
  • 希望控制分页外观的UI设计师

使用建议

  • 不会自动处理数据加载
  • 需要手动管理页面切换的状态
  • 仅限数值分页(无无限滚动)
  • 未针对页数极多的情况进行优化
  • 无内置的可访问性功能支持

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Pager

Numeric pagination suitable for multiple cases, such as, custom paged table.

Getting started

You should ensure that you add the pager as a dependency in your flutter project.

dependencies:
 pager: ^0.0.6

Example Project

There is a example project in the example folder. Check it out. Otherwise, keep reading to get up and running.

Usage

Need to include the import the package to the dart file where it will be used, use the below command,

import 'package:pager/pager.dart';

Pager

Basic Widget


new Pager(
            currentPage: _currentPage,
            totalPages: 5,
            onPageChanged: (page) {},
          ),

Example 1

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Pagination Example"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              height: 200,
              margin: const EdgeInsets.all(32),
              color: Colors.blue,
              child: Center(
                child: Text(
                  "PAGE: $_currentPage",
                  style: const TextStyle(color: Colors.white, fontSize: 20),
                ),
              ),
            ),
            Pager(
              currentPage: _currentPage,
              totalPages: 5,
              onPageChanged: (page) {
                setState(() {
                  _currentPage = page;
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}

Complete example 2

import 'package:flutter/material.dart';
import 'package:pager/pager.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Pagination Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({
    Key? key,
  }) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late int _currentPage;
  late int _itemsPerPage;
  List<int> pages = [5, 10, 18, 50, 100];
  late int _totalPages;
  final int _totalElements = 100;
  @override
  void initState() {
    super.initState();
    _currentPage = 1;
    _itemsPerPage = pages.first;
    _totalPages = (_totalElements / _itemsPerPage) as int;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Pagination Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Pagination Example'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(32.0),
          child: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  height: 180,
                  width: 400,
                  color: Colors.blue,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      Text(
                        "TOTAL ELEMENT: $_totalElements",
                        style:
                            const TextStyle(color: Colors.white, fontSize: 18),
                      ),
                      Text(
                        "PAGE: $_currentPage",
                        style:
                            const TextStyle(color: Colors.white, fontSize: 18),
                      ),
                      Text(
                        "ITEMS PER PAGE: $_itemsPerPage",
                        style:
                            const TextStyle(color: Colors.white, fontSize: 18),
                      ),
                      Text(
                        "TOTAL PAGES: $_totalPages",
                        style:
                            const TextStyle(color: Colors.white, fontSize: 18),
                      ),
                    ],
                  ),
                ),
                const SizedBox(height: 32),
                Pager(
                  currentItemsPerPage: _itemsPerPage,
                  currentPage: _currentPage,
                  totalPages: _totalPages,
                  onPageChanged: (page) {
                    setState(() {
                      _currentPage = page;
                    });
                  },
                  showItemsPerPage: true,
                  onItemsPerPageChanged: (itemsPerPage) {
                    setState(() {
                      _itemsPerPage = itemsPerPage;
                      _totalPages = (_totalElements / _itemsPerPage).ceil();
                      _currentPage = 1;
                    });
                  },
                  itemsPerPageList: pages,
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

所属分类

源码仓库

使用此插件的项目

暂无相关数据。