项目作者: BakerJQ

项目描述 :
An infinite card switching UI for Flutter, support custom animation 自定义实现神奇动效的卡片切换视图
高级语言: Dart
项目地址: git://github.com/BakerJQ/Flutter-InfiniteCards.git


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

  1. cd ./example
  2. flutter create .
  3. flutter run

How to use

Add dependencies

  1. dependencies:
  2. infinite_cards: ^1.0.3

Build controller in initState

  1. @override
  2. void initState() {
  3. super.initState();
  4. _controller = InfiniteCardsController(
  5. itemBuilder: _renderItem,
  6. itemCount: 5,
  7. animType: AnimType.SWITCH,
  8. );
  9. }
  • 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

  1. InfiniteCards(
  2. controller: _controller,
  3. )

Call methods from controller

  1. _controller.previous();
  2. _controller.next();
  3. _controller.reset(...);

Animation transform and curve

Default

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

Customisation

  1. InfiniteCardsController(
  2. ...
  3. transformToFront: yourCustomTransformToFront,
  4. transformToBack: yourCustomTransformToBack,
  5. curve: yourCustomCurve
  6. ...
  7. )

One example of implement Transform

  1. Transform _defaultCommonTransform(Widget item,
  2. double fraction, double curveFraction, double cardHeight, double cardWidth, int fromPosition, int toPosition)
  3. {
  4. //Count of card which needs to move over
  5. int positionCount = fromPosition - toPosition;
  6. //0.8 scale for the first card, and -0.1 per card behind
  7. //(0.8 - 0.1 * fromPosition) = current specific card scale
  8. //(0.1 * fraction * positionCount) = scale while moving
  9. double scale = (0.8 - 0.1 * fromPosition) + (0.1 * fraction * positionCount);
  10. //translate -0.02 * cardHeight per card behind
  11. //-cardHeight * (0.8 - scale) * 0.5 to center the card
  12. double translationY = -cardHeight * (0.8 - scale) * 0.5 -
  13. cardHeight * (0.02 * fromPosition - 0.02 * fraction * positionCount);
  14. //return the Widget after scale and translate
  15. return Transform.translate(
  16. offset: Offset(0, translationY),
  17. child: Transform.scale(
  18. scale: scale,
  19. child: item,
  20. ),
  21. );
  22. }

License

InfiniteCards is released under the Apache 2.0 license.

  1. Copyright 2019 BakerJ.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at following link.
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.