swipeable_cards_stack

这是一个类似Tinder的可滑动卡片包。你可以添加自己的组件到堆栈中,接收所有四个事件,左滑、右滑、上滑和下滑。你可以为每个方向定义自己的业务逻辑。

Demo

文档

安装

swipeable_cards_stack 添加到你的 pubspec.yaml

dependencies:
  swipeable_cards_stack: <latest version>

用法

使用包提供的 SwipeableCardsStack 组件

import 'package:swipeable_cards_stack/swipeable_cards_stack.dart';

class MyWidget extends StatefulWidget {
  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  final _cardsController = SwipeableCardsStackController();

  @override
  Widget build(BuildContext context) {
    return SwipeableCardsStack(
      cardController: _cardsController,
      context: context,
      // Add the first 3 cards (widgets)
      items: [
        CardView(text: "First card"),
        CardView(text: "Second card"),
        CardView(text: "Third card"),
      ],
      // Get card swipe event callbacks
      onCardSwiped: (dir, index, widget) {
        // Add the next card using _cardController
        _cardsController.addItem(CardView(text: "Next card"));

        // Take action on the swiped widget based on the direction of swipe
        // Return false to not animate cards
      },
      enableSwipeUp: true,
      enableSwipeDown: false,
    );
  }
}

贡献

如果你想为这个项目贡献代码,你可以轻松地创建 issue 并发送 PR。请注意,你的代码贡献将适用 MIT 许可,除非另有说明。

鸣谢

GitHub

查看 Github