Giter Site home page Giter Site logo

anupkumarpanwar / swipe_cards Goto Github PK

View Code? Open in Web Editor NEW
49.0 2.0 44.0 1.17 MB

Tinder like swipe cards for flutter.

Home Page: https://pub.dev/packages/swipe_cards

License: BSD 3-Clause "New" or "Revised" License

Kotlin 0.46% Swift 1.51% Objective-C 0.14% Dart 97.88%
swipe-cards tinder dart flutter pubdev

swipe_cards's Introduction

swipe_cards pub package

A Flutter widget for Tinder like swipe cards. The card can be swiped right, left and up for different responses. Currently it supports the following responses:

  • Right swipe for like
  • Left swipe for nope
  • Up swipe for superlike

Install

To install the package, add the following dependency to your pubspec.yaml

dependencies:
  swipe_cards: ^2.0.0+1

Usage

Basic

import 'package:swipe_cards/swipe_cards.dart';

SwipeCards(
            matchEngine: <MatchEngine>,
            itemBuilder: (BuildContext context, int index) {},
            onStackFinished: () {},
            itemChanged: (SwipeItem item, int index) {},
            upSwipeAllowed: <bool>,
            fillSpace: <bool>,
);

Attributes of SwipeCards

Key Description
matchEngine An instance of MatchEngine that acts as controller for trigerring swipes manually.
itemBuilder A function that returns the view inside a swipe card.
likeTag Widget appears in like/right area during swipe.
nopeTag Widget appears in nope/left area during swipe.
superLikeTag Widget appears in super-like/up area during swipe.
onStackFinished A function that is triggered as soon as all the cards have been swiped.
itemChanged A function that is triggered when item in the stack changes (moves to next card).
leftSwipeAllowed To enable/disable left swipe. (Default: true)
rightSwipeAllowed To enable/disable right swipe. (Default: true)
upSwipeAllowed To enable/disable up swipe. (Default: false)
fillSpace Config weather to fill up the space or not. (Default: true)

MatchEngine

MatchEngine is the controller for the swipe cards. It takes swipeItems as an argument and is used to trigger the swipes manually, for example on button press. The data type of swipeItems is List<SwipeItem>.

MatchEngine _matchEngine = MatchEngine(swipeItems: List<SwipeItem>);

Functions in MatchEngine

Key Description
_matchEngine.currentItem.like(); To trigger right swipe manually.
_matchEngine.currentItem.nope(); To trigger left swipe manually.
_matchEngine.currentItem.superLike(); To trigger up swipe manually.

SwipeItem

SwipeItem contains the actual data that can be rendered in the swipe card. Actually it is a wrapper over any dynamic object and just adds the functionality of like, nope and superlike to that object.

SwipeItem(
            content: "Anup Kumar Panwar",
            likeAction: () {
                log("Like");
            },
            nopeAction: () {
                log("Nope");
            },
            superlikeAction: () {
                log("Superlike");
            },
            onSlideUpdate: (SlideRegion? region){
                log("Region $region");
            }
);

Attributes of SwipeItem

Key Description
content An object that contains the actual data to be rendered in the swipe card.
likeAction A function that is triggered when the card is liked.
nopeAction A function that is triggered when the card is not liked / swiped left.
superlikeAction A function that is triggered when the card is superliked.
onSlideUpdate A function that is triggered when the card is being dragged and tells about the current region of the card.

Example

List<SwipeItem> _swipeItems = List<SwipeItem>();
  MatchEngine _matchEngine;
  GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
  List<String> _names = ["Red", "Blue", "Green", "Yellow", "Orange"];
  List<Color> _colors = [
    Colors.red,
    Colors.blue,
    Colors.green,
    Colors.yellow,
    Colors.orange
  ];

  @override
  void initState() {
    for (int i = 0; i < _names.length; i++) {
      _swipeItems.add(SwipeItem(
          content: Content(text: _names[i], color: _colors[i]),
          likeAction: () {
            ScaffoldMessenger.of(context).showSnackBar(SnackBar(
              content: Text("Liked ${_names[i]}"),
              duration: Duration(milliseconds: 500),
            ));
          },
          nopeAction: () {
            ScaffoldMessenger.of(context).showSnackBar(SnackBar(
              content: Text("Nope ${_names[i]}"),
              duration: Duration(milliseconds: 500),
            ));
          },
          superlikeAction: () {
            ScaffoldMessenger.of(context).showSnackBar(SnackBar(
              content: Text("Superliked ${_names[i]}"),
              duration: Duration(milliseconds: 500),
            ));
          },
          onSlideUpdate: (SlideRegion? region) async {
            print("Region $region");
          }));
    }

    _matchEngine = MatchEngine(swipeItems: _swipeItems);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        key: _scaffoldKey,
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Container(
            child: Column(children: [
          Container(
            height: 550,
            child: SwipeCards(
              matchEngine: _matchEngine,
              itemBuilder: (BuildContext context, int index) {
                return Container(
                  alignment: Alignment.center,
                  color: _swipeItems[index].content.color,
                  child: Text(
                    _swipeItems[index].content.text,
                    style: TextStyle(fontSize: 100),
                  ),
                );
                  },
                  onStackFinished: () {
                    ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                      content: Text("Stack Finished"),
                      duration: Duration(milliseconds: 500),
                    ));
                  },
                  itemChanged: (SwipeItem item, int index) {
                    print("item: ${item.content.text}, index: $index");
                  },
                  upSwipeAllowed: true,
                  fillSpace: true,
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  RaisedButton(
                      onPressed: () {
                        _matchEngine.currentItem.nope();
                      },
                      child: Text("Nope")),
                  RaisedButton(
                      onPressed: () {
                        _matchEngine.currentItem.superLike();
                      },
                      child: Text("Superlike")),
                  RaisedButton(
                      onPressed: () {
                        _matchEngine.currentItem.like();
                      },
                      child: Text("Like"))
                ],
              )
            ])));
  }
  class Content {
    final String text;
    final Color color;

    Content({this.text, this.color});
  }

Screenshot

Screenshot

swipe_cards's People

Contributors

anupkumarpanwar avatar devsalmangithub avatar omar-salem avatar rashid-khabeer avatar sipi1020 avatar yagizdo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

swipe_cards's Issues

Dispose slideOutAnimation

Hello,

It seems that in "draggable_card.dart" the AnimationController slideOutAnimation should be disposed in dispose method like the slideBackAnimation is ?

Show stacked cards in different positions to deck effect

Hi there, I'm using this plugin and I would like to know if is possible to show the complete stack each card with a different top position relative between each other, that way the user can see the full stack of cards, this is to create a deck effect and give more visibility to the user.
thanks

edit to the plugin....

  1. i want to add if swipe up it should not remove from the list.
    2 i want to add swipe down.

can u help with seperate repo for this or add option to the plugins

Swipe Update CallBack

Hey I think there is need of onSwipeUpdateCallback just like

onSwipeUpdateCallback(DragUpdateDetails details, Alignment align) { }

I need drapupdatedetails and Alignment or offset while swiping a card.
Thanks

Need loop functionality

Please provide loop functionality. If the images are completed then the black page is showing.

The getter 'width' was called on null.

This L287 throwing an error of The getter 'width' was called on null.

Is there a way to fix this?

List<SwipeItem> _swipeItems = [];

final MatchEngine matchEngine = new MatchEngine(
    swipeItems: edges.map((edge) {
  final post = Post.fromJson(edge);
  final swipeItem = SwipeItem(
    content: post,
    likeAction: () {
      launchURL(post.node.slug);
    },
  );
  _swipeItems.add(swipeItem);
  return swipeItem;
}).toList());
return MyHomePage(
  matchEngine: matchEngine,
  swipeItems: _swipeItems,
);

Using it as follows.
Then in MyHomePage

Scaffold(
      appBar: _buildAppBar(),
      body: Center(
        child: Container(
          constraints: BoxConstraints(
            minWidth: 300,
            maxWidth: 500,
            maxHeight: 730,
          ),
          padding: EdgeInsets.all(10),
          child: SwipeCards(
            matchEngine: matchEngine,
            itemBuilder: (BuildContext context, int index) {
              return ProfileCard(
                post: swipeItems[index].content,
              );
            },
            onStackFinished: () {
              print('finished');
            },
          ),
        ),
      ),
      bottomNavigationBar: _buildBottomBar(),
);

Disable swipe up and down

An ability to configure swipes directions would be really great.

final allowedActions = [
    SwipeDirection.right,
    SwipeDirection.left,
];

Something like this or

final notAllowedActions = [
    SwipeDirection.up,
    SwipeDirection.down,
];

Add function for when front-card is mounted

In my app I use a textField inside of a SwipeItem sometimes.

When autofocus: true is set, the keyboard opens automatically causing the cards to re-size. This is the expected behaviour, but if the card behind has a textField and the card infront does not, the keyboard is opened also.

Is there anyway from inside the SwipeItem to tell if it's the current item? or a callback that fires when it becomes the current item?

thanks,
Jesse,

Thank you for this package but Match card stops working after re-initializing MatchMachine

I want to say a big thank you for creating this package. I love your package and it is helpful

I wanted to make sure that cards on the stack did not finish from the stack, so I re-initialized like below:

  void initState() {
    super.initState();
    _init();
  }

  void _init() {
    for (int i = 0; i < matches.length; i++) {
      _swipeItems.add(
        SwipeItem(
          content: MatchData(
              image: matches[i].image,
              userName: matches[i].userName,
              age: matches[i].age,
              gender: matches[i].gender,
              role: matches[i].role,
              travelingTo: matches[i].travelingTo,
              opt1: matches[i].opt1,
              opt2: matches[i].opt2,
              isVerified: matches[i].isVerified,
              numberOfTipsGiven: matches[i].numberOfTipsGiven,
              startMonth: matches[i].startMonth,
              endMonth: matches[i].endMonth,
              travelYear: matches[i].travelYear,
              travelAideRating: matches[i].travelAideRating,
              selectedOpt: matches[i].selectedOpt),
        ),
      );
    }
    _matchEngine = MatchEngine(swipeItems: _swipeItems);
    Provider.of<RequestProvider>(context, listen: false).matchEngine =
        _matchEngine!;
  }```

but methods from the matchmachine which I believe is the Controller, stops working unexpectedly

``` widget.matchEngine.currentItem?.nope();

How do I resolve this?

Back card not loading issue

When you swipe the card lightly and the card is not dragged, then when you swipe again it doesn't load next card and shows a white screen instead, then it loads when the swiping is fully completed. This happens then for all the remaining cards on the stack.
Swipe_Card_issue

matchEngine.rewindMatch() gives an error on last card

If you swipe through all of the cards, and then undo the last one using matchEngine.rewindMatch(), you get a Null error.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value

Back card does not preload until the front card is fully swiped

Whenever a card is being dragged, the back card will still show the same content of the front card.

The content of the back card is only loaded when the front card is completely swiped; in the meantime it will still show the swiped card content.

Attached you can find evidence of this behavior. I followed the example from pub.dev to create the stack as well.

Screen.Recording.2022-03-30.at.6.26.23.PM.mov

Shadow bug

Quite minor issue.

When card has a shadow, the initial shadow is darker than it should. It's visible in the video from the other issue:
#13

Notice how the shadow gets darker when the card loads.

I guess it could be caused by the bottom card not being applied the 0.9 transformation on initial render, but seemed good in the code, so not sure.

Swipe is not working with admob banner ads

Hello, I have added an admob banner on the swipe card, and when I try to swipe, it is not working correctly.
When I swipe the card, it getting returning back and stuck the swipe

Back card swiped

Sometimes back card swiped. Please do the needful. I am attached the video, Please go through it.

Uploading 2021_08_18_17_10_45_trim.mp4…

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.