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

GitHub 代码仓BakerJQ/Flutter-InfiniteCards

Flutter-无限卡片

适用于 Flutter 的无限卡片切换界面,支持自定义动画

Flutter-无限卡片 项目封面
星标
363
复刻
51
最近推送(UTC)
2019年5月15日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

InfiniteCards

License pub package

An infinite card switching UI for Flutter, support custom animation 可自定义动效的卡片切换视图(中文文档)

Android version

https://github.com/BakerJQ/Android-InfiniteCards

Flutter for Web version

https://github.com/BakerJQ/Flutter-InfiniteCards/tree/web

Screenshot

Android iOS

Example

cd ./example
flutter create .
flutter run

How to use

Add dependencies
dependencies:
  infinite_cards: ^1.0.3
Build controller in initState
@override
  void initState() {
    super.initState();
    _controller = InfiniteCardsController(
      itemBuilder: _renderItem,
      itemCount: 5,
      animType: AnimType.SWITCH,
    );
  }
  • animType : animation type
    • TO_FRONT : move the selected card to first
    • SWITCH : move the selected card to first, and the first card to the selected position
    • TO_END : move the first card to last position
Build widget with controller
InfiniteCards(
  controller: _controller,
)
Call methods from controller
  _controller.previous();
  _controller.next();
  _controller.reset(...);
Animation transform and curve
Default

If you just use all default animations, just do nothing.

Customisation
InfiniteCardsController(
            ...
            transformToFront: yourCustomTransformToFront,
            transformToBack: yourCustomTransformToBack,
            curve: yourCustomCurve
            ...
          )

One example of implement Transform

Transform _defaultCommonTransform(Widget item, 
    double fraction, double curveFraction, double cardHeight, double cardWidth, int fromPosition, int toPosition) 
  {
  //Count of card which needs to move over
  int positionCount = fromPosition - toPosition;
  //0.8 scale for the first card, and -0.1 per card behind
  //(0.8 - 0.1 * fromPosition) = current specific card scale
  //(0.1 * fraction * positionCount) = scale while moving
  double scale = (0.8 - 0.1 * fromPosition) + (0.1 * fraction * positionCount);
  //translate -0.02 * cardHeight per card behind
  //-cardHeight * (0.8 - scale) * 0.5 to center the card
  double translationY = -cardHeight * (0.8 - scale) * 0.5 -
      cardHeight * (0.02 * fromPosition - 0.02 * fraction * positionCount);
  //return the Widget after scale and translate
  return Transform.translate(
    offset: Offset(0, translationY),
    child: Transform.scale(
      scale: scale,
      child: item,
    ),
  );
}

License

InfiniteCards is released under the Apache 2.0 license.

Copyright 2019 BakerJ.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at following link.

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
BakerJ GitHub avatar
GitHub 作者

BakerJ ↗

Only cowards don't stand up to a challenge

Nanchang, China官方网站 ↗
语言Dart

分类

此仓库发布的插件

使用的依赖

依赖清单 3 项

  • flutter{"sdk":"flutter"}
  • cupertino_icons^0.1.2
  • flutter_test开发依赖{"sdk":"flutter"}

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗