搜尋套件、儲存庫與 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,
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。