搜索分类、插件与代码仓

dots_indicator 封面
插件详情v5.0.0

dots_indicator

用于显示 PageView 进度的圆点指示器,例如

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
17.8万
喜欢数
768
Pub 分数
160

安装插件

flutter pub add dots_indicator

插件介绍

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

一个 Flutter 包,提供视觉上的点状指示器,用于显示在 PageView 等可滚动小部件中的当前位置。它帮助用户了解自己在一系列页面或幻灯片中的进度,支持自定义点的外观和行为。该指示器支持多种主题、大小和动画,非常适合用于引导界面、图片轮播和向导式体验。轻量级且兼容所有主要平台。

适合场景

  • 入门屏幕
  • 图片滑块
  • 导览游
  • 表单向导
  • 轮播导航
  • 幻灯片指示器

主要特点

  • 可定制的点大小和颜色
  • 页面之间的平滑动画
  • 支持多种主题
  • 响应式设计
  • 与 PageView 的轻松集成
  • Platform-agnostic

适合对象

  • 移动应用开发者
  • UI/UX 设计师
  • 入门流程
  • 交互式教程
  • 多页内容显示

使用建议

  • 需要与 PageView 手动同步
  • 超出样式之外的自定义功能有限
  • 无内置滑动手势
  • 不适用于不可滚动的内容
  • 可能需要额外的状态管理

原始 README

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

dots_indicator

Widget to display dots indicator to show a position (for a PageView for example).

Installation

You just need to add dots_indicator as a dependency in your pubspec.yaml file.

dependencies:
  dots_indicator: ^5.0.0

Breaking change in 5.0.0: this package now uses the standalone material_ui package instead of package:flutter/material.dart. Your app must also use material_ui (or keep the deprecated MaterialUiCompatibilityBridge), otherwise tapping a dot (onTap) throws No Material widget found. Requires Flutter >=3.44.0 and Dart ^3.12.0. See the CHANGELOG for details.

Quick start

The typical use case is to pair DotsIndicator with a PageView, syncing position to the controller's current page:

class MyPageView extends StatefulWidget {
  const MyPageView({super.key});

  @override
  State<MyPageView> createState() => _MyPageViewState();
}

class _MyPageViewState extends State<MyPageView> {
  final _pages = const [Page1(), Page2(), Page3()];
  final _pageController = PageController();
  double _currentPage = 0;

  @override
  void initState() {
    super.initState();
    _pageController.addListener(() {
      setState(() => _currentPage = _pageController.page ?? 0);
    });
  }

  @override
  void dispose() {
    _pageController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Expanded(
          child: PageView(controller: _pageController, children: _pages),
        ),
        DotsIndicator(
          dotsCount: _pages.length,
          position: _currentPage,
        ),
      ],
    );
  }
}

You can also drive DotsIndicator manually (no PageView), or let it drive navigation itself with onTap — see below.

Example

In these examples, pageLength is the total of dots to display and currentPage is the position to highlight (the active dot).

For information, currentPage is a double, to be able to have lerp animation.

A simple dots indicator

Simple dots

DotsIndicator(
  dotsCount: pageLength,
  position: currentPage,
);
Custom colors

Custom dots colors

DotsIndicator(
  dotsCount: pageLength,
  position: currentPage,
  decorator: DotsDecorator(
    color: Colors.black87, // Inactive color
    activeColor: Colors.redAccent,
  ),
);
Use specific color for each dot

You can choose to have one color for inactive dots and one color the active dot.

But you can also define one color by inactive dots (colors) and one color by active dot (activeColors).

If you have a total of 3 dots, you must provide an array of 3 colors.

DotsIndicator(
  dotsCount: pageLength,
  position: currentPage,
  decorator: DotsDecorator(
    colors: [Colors.grey[300], Colors.grey[600], Colors.grey[900]], // Inactive dot colors
    activeColors: [Colors.red[300], Colors.red[600], Colors.red[900]], // Àctive dot colors
  ),
);
Custom size and shape

You can change the default size of dots and also shape.

So you can choose to have a shape for inactive dots and another shape for the active dot for example.
By default, the shape of dots are CircleBorder, so to have a rounded rectangle for active one, you need to change activeShape

Custom dots size

DotsIndicator(
  dotsCount: pageLength,
  position: currentPage,
  decorator: DotsDecorator(
    size: const Size.square(9.0),
    activeSize: const Size(18.0, 9.0),
    activeShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
  ),
);
Custom size for each dot

You can customize the size of each dot, for inactive and/or active dots.

For that, use sizes and/or activeSizes params.

DotsIndicator(
  dotsCount: pageLength,
  position: currentPage,
  decorator: DotsDecorator(
    sizes: [
      const Size.square(10.0),
      const Size.square(15.0),
      const Size.square(20.0),
    ],
    activeSizes: [
      const Size.square(25.0),
      const Size.square(25.0),
      const Size.square(35.0),
    ],
  ),
);
Custom shape

You can change the default shape of dots. By default it's a CircleBorder.

You can change the no active and active dot shape.

Custom dots shape

DotsIndicator(
  dotsCount: pageLength,
  position: currentPage,
  decorator: DotsDecorator(
    shape: const Border(),
    activeShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
  ),
);
Custom shape for each dot

You can customize the shape of each dot, for inactive and/or active dots.

For that, use shapes and/or activeShapes params.

DotsIndicator(
  dotsCount: pageLength,
  position: currentPage,
  decorator: DotsDecorator(
    shapes: [
      RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
      RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
      RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
    ],
    activeShapes: [
      RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
      RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
      RoundedRectangleBorder(borderRadius: BorderRadius.circular(25.0)),
    ],
  ),
);
Change the space between dots

By default a dot have a margin of 6 pixels on his left and right. It's EdgeInsets.symmetric(horizontal: 6.0). But if you want you can change it, for example to increase the space between dots or to add top margin.

Custom dots space

DotsIndicator(
  dotsCount: pageLength,
  position: currentPage,
  decorator: DotsDecorator(
    spacing: const EdgeInsets.all(10.0),
  ),
);
Axis and reverse property

There is two other property, axis and reversed. Axis is to display dots indicator horizontally (default) or vertically. Also, you can set reversed: true to reverse the order of dots. (default: false).

For example, if you want to display the dots indicator vertically, but with the first dots on bottom : Set axis: Axis.vertical and reversed: true. Obviously, you can use reversed with Axis.horizontal.

DotsIndicator(
  dotsCount: pageLength,
  position: currentPage,
  axis: Axis.vertical,
  reversed: true,
);
onTap property

Add the onTap property to let users jump directly to a page by tapping its dot, instead of only reflecting the current page.

DotsIndicator(
  dotsCount: pageLength,
  position: currentPage,
  onTap: (index) {
    _pageController.animateToPage(
      index,
      duration: const Duration(milliseconds: 300),
      curve: Curves.ease,
    );
  },
);
Fade out the last dot (indefinite pager)

When dotsCount is large (or unknown), showing every dot isn't practical. Set fadeOutLastDot: true with a fadeOutDistance to only keep a window of dots fully visible around the current position, fading the rest out — and animate: true to transition smoothly as position changes.

DotsIndicator(
  dotsCount: pageLength,
  position: currentPage,
  fadeOutLastDot: true,
  fadeOutDistance: 2,
  animate: true,
);

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目