Giter Site home page Giter Site logo

flutter_card_swiper's Introduction

flutter_card_swiper

Pub Version Pub Points Pub Likes Pub popularity Tests codecov

This is a Flutter package for a Tinder-like card swiper. โœจ

It allows you to swipe left, right, up, and down and define your own business logic for each direction.

Very smooth animations supporting Android, iOS, Web & Desktop.

Why?

We built this package because we wanted to:

  • Have a fully customizable slider
  • Swipe in any direction
  • Undo swipes as many times as you want
  • Choose your own settings such as duration, angle, padding and more
  • Trigger swipes in any direction with the controller
  • Add callbacks while swiping, on end, or when the swiper is disabled
  • Detect the direction (left, right, top, bottom) the card was swiped

Show Cases

Swipe in any direction Trigger swipes Unswipe the cards
Fully customizable

Installation

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

card_swiper: ...

OR run

flutter pub add flutter_card_swiper

in your project's root directory.

Usage

You can place your CardSwiper inside of a Scaffold like we did here. Optional parameters can be defined to enable different features. See the following example:

import 'package:flutter_card_swiper/flutter_card_swiper.dart';
import 'package:flutter/material.dart';

class Example extends StatelessWidget {
  List<Container> cards = [
    Container(
      alignment: Alignment.center,
      child: const Text('1'),
      color: Colors.blue,
    ),
    Container(
      alignment: Alignment.center,
      child: const Text('2'),
      color: Colors.red,
    ),
    Container(
      alignment: Alignment.center,
      child: const Text('3'),
      color: Colors.purple,
    )
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Flexible(
        child: CardSwiper(
          cardsCount: cards.length,
          cardBuilder: (context, index) => cards[index],
        ),
      ),
    );
  }
}

Constructor

Basic

Parameter Default Description Required
cardBuilder - Widget builder for rendering cards true
cardsCount - Number of cards true
controller - Controller to trigger swipe actions false
direction right Direction in which the card is swiped away when triggered from the controller false
duration 200 milliseconds The duration that every animation should last false
initialIndex 0 Index of the first card when the swiper is initialized false
isDisabled false Set to true if swiping should be disabled, has no impact when triggered from the outside false
isHorizontalSwipingEnabled (deprecated) true Set to false if you want your card to move only across the vertical axis when swiping. (Deprecated: use allowedSwipeDirection instead) false
isLoop true Set to true if the stack should loop false
isVerticalSwipingEnabled (deprecated) true Set to false if you want your card to move only across the horizontal axis when swiping. (Deprecated: use allowedSwipeDirection instead) false
maxAngle 30 Maximum angle that the card can reach during swiping false
allowedSwipeDirection AllowedSwipeDirection.all Sets the direction in which the card can be swiped. It can be set to any combination of left, right up or down. false
numberOfCardsDisplayed 2 Number of cards displayed at the same time false
onEnd - Callback when there are no more cards left to swipe false
onSwipe - Callback when the user swipes a card. If the function returns false, the swipe action is canceled. If it returns true, the swipe action is performed as expected false
onTapDisabled - Callback when a card is tapped and isDisabled is true false
onUndo - Callback when the controller calls undo. If the function returns false, the undo action is canceled. If it returns true, the undo action is performed as expected false
padding EdgeInsets.symmetric(horizontal: 20, vertical: 25) The padding around the swiper false
scale 0.9 Scale of the card that is behind the front card false
threshold 50 Threshold from which the card is swiped away false

Controller

The Controller is used to swipe the card from outside of the widget. You can create a controller called CardSwiperController and save the instance for further usage. Please have a closer look at our Example for the usage.

Method Description
swipe Swipes the card in the selected direction.
swipeLeft Swipes the card to the left side.
swipeRight Swipes the card to the right side.
swipeTop Swipes the card to the top side.
swipeBottom Swipes the card to the bottom side.
undo Bring back the last card that was swiped away.

Credits

  • Ricardo Dalarme (Package maintainer)
  • Appinio GmbH (Original project creator)

flutter_card_swiper's People

Contributors

ricardodalarme avatar jawwad-hassan89 avatar basemosama avatar giboin avatar andrea689 avatar richertc avatar kzrnm avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.