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

page_animator 封面
插件详情v1.0.1

page_animator

一个提供流畅页面过渡和动画的 Flutter 包,支持自定义效果。非常适合创建具有水平页面导航的引人入胜的用户界面。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
14
喜欢数
9
Pub 分数
160

安装插件

flutter pub add page_animator

插件介绍

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

PageAnimator 是一个专为 Flutter 设计的包,旨在为水平导航提供流畅、可自定义的页面过渡和动画效果。它通过流体视觉效果增强用户界面,使应用导航更加生动且直观。适用于需要动态屏幕切换的应用场景,如引导流程、仪表板或多步骤流程。该包支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,确保在各种设备上保持一致的性能。

适合场景

  • 引导屏幕
  • 仪表板导航
  • 多步骤表单
  • 交互式教程
  • 可滑动内容
  • 动画标签切换

主要特点

  • 可自定义的过渡效果
  • 平滑的水平页面动画
  • 跨平台兼容性
  • 与 PageView 的轻松集成
  • 支持基于手势的导航
  • 可配置的持续时间和曲线

适合对象

  • 寻求动画导航的开发者
  • 具有可滑动界面的应用
  • 注重设计的UI实现
  • 具有丰富交互功能的移动和Web应用
  • 注重用户体验的团队

使用建议

  • 可能会影响复杂动画的性能
  • 需要仔细调整以获得最佳用户体验
  • 有限的内置预设(需要自定义)
  • 不适合简单的静态页面
  • 最适合中等动画复杂度

原始 README

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

Page Animator

A Flutter package that provides smooth page transitions and animations with customizable effects. Perfect for creating engaging user interfaces with horizontal page navigation.

Features

  • Multiple animation types for page transitions, switchable in realtime
  • Infinite scrolling in both directions, with ability to set bounds in realtime
  • Animated switcher - tap on a page, and it will zoom out, similar to Kindle reader
  • Immersive mode support

Animation Types

The package supports various animation types through PageAnimatorType. Here's a comprehensive list of all available animations:

Preview Preview Preview
Uncompressed gif
animatedSwitcher - Animated switcher transition
Uncompressed gif
noAnimation - No animation effect, instant page switch
Uncompressed gif
horizontalSimple - Simple horizontal slide transition
Uncompressed gif
horizontalFade - Horizontal slide with fade effect
Uncompressed gif
horizontalFadeInverse - Horizontal slide with inverse fade effect
Uncompressed gif
verticalSimple - Simple vertical slide transition
Uncompressed gif
verticalFade - Vertical slide with fade effect
Uncompressed gif
verticalFadeInverse - Vertical slide with inverse fade effect

You can change the animation type dynamically using the controller:

pageAnimatorController.type.value = PageAnimatorType.verticalFade;

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  page_animator: ^1.0.0

Usage

  1. Import the package:
import 'package:page_animator/page_animator.dart';
  1. Create a PageAnimatorController:
final pageAnimatorController = PageAnimatorController(
  type: PageAnimatorType.horizontalFade,
);
  1. Use the PageAnimator widget:
PageAnimator(
  controller: pageAnimatorController,
  onPageChanged: (int currentPage) {
    print('Page offset: $currentPage');
  },
  leftMostIndex: -3,
  rightMostIndex: 3,
  children: [
    // Your page widgets here
  ],
  enableImmersiveSwitch: true,
)
Page Bounds

The PageAnimator widget allows you to set bounds for page navigation using leftMostIndex and rightMostIndex parameters:

  • leftMostIndex: The minimum page offset that can be reached by swiping left
  • rightMostIndex: The maximum page offset that can be reached by swiping right

These bounds can be changed in realtime, allowing you to dynamically control the navigation range. For example:

// Initially allow navigation indefinitelly
PageAnimator(
  leftMostIndex: null,
  rightMostIndex: null,
  // ... other parameters
)

// Later, you can update the bounds
PageAnimator(
  leftMostIndex: -3,
  rightMostIndex: 3,
  // ... other parameters
)

When a bound is reached, the page will stop scrolling in that direction, providing a natural end to the navigation.

Example

Here's a complete example showing how to use the package:

class MyPage extends StatefulWidget {
  @override
  State<MyPage> createState() => _MyPageState();
}

class _MyPageState extends State<MyPage> {
  final pageAnimatorController = PageAnimatorController(
    type: PageAnimatorType.horizontalFade,
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageAnimator(
        controller: pageAnimatorController,
        onPageChanged: (int currentPage) {
          print('Page offset: $currentPage');
        },
        leftMostIndex: -3,
        rightMostIndex: 3,
        children: [
          for (final page in List.generate(3, (index) => index))
            _buildPage(page),
        ],
        enableImmersiveSwitch: true,
      ),
    );
  }

  Widget _buildPage(int page) {
    return Scaffold(
      body: Center(
        child: Text('Page $page'),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => pageAnimatorController.animateToOffset(1),
        child: const Icon(Icons.skip_next),
      ),
    );
  }
}

Controller Methods

The PageAnimatorController provides several methods to control page transitions:

  • animateToOffset(int offset): Animate to a specific page offset
  • type: Change the animation type dynamically
  • switcherActive: Control the page switcher state

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Parameters

  • children: List of widgets to display as pages
  • onPageChanged: Callback when page is changed
  • leftMostIndex: The first page user can go to
  • rightMostIndex: The last page user can go to
  • controller: PageAnimatorController instance
  • enableImmersiveSwitch: Optional boolean that controls whether to enable immersive mode while switcher is inactive, and automatically disable it when user enters switcher. If not specified, defaults to true.
  • onDragStart: Optional callback when drag starts
  • onDragEnd: Optional callback when drag ends
  • onDragAnimationStart: Optional callback when animation starts
  • onDragAnimationEnd: Optional callback when animation ends

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。