简体   繁体   中英

Flutter - Press button to make a card swipe

so I'm using TinderSwapCard, the swipeCompleteCallback is working good, I just want to add 2 buttons, to have the same animation of swiping by pressing the button.

how I can do that?

thanks in advance.

a picture of the app

here is the code used :

new TinderSwapCard(
                    orientation: AmassOrientation.TOP,
                    swipeUp: false,
                    swipeDown: false,
                    totalNum: list.length,
                    stackNum: 4,
                    maxHeight: MediaQuery.of(context).size.width*1.7,
                    maxWidth: MediaQuery.of(context).size.width*0.9,
                    minHeight: MediaQuery.of(context).size.width*0.9,
                    minWidth: MediaQuery.of(context).size.width*0.6,
                    cardBuilder: (context,index)=>Card(
                      color: Colors.black,
                      child: Column(
                        children: [
                              new Image.asset(
                              list[index],
                              fit: BoxFit.fill,
                              ),
                              Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              RawMaterialButton(
                                fillColor: Colors.white,
                                child: FaIcon(FontAwesomeIcons.times,size: 50.0,color: Colors.red,),
                                shape: CircleBorder(),
                                padding: const EdgeInsets.all(8.0),
                                onPressed: (){
                                  //what to do here ?
                              },),
                              RawMaterialButton(
                                fillColor: Colors.white,
                                child: FaIcon(FontAwesomeIcons.solidHeart,size: 50.0,color: Colors.green,),
                                shape: CircleBorder(),
                                padding: const EdgeInsets.all(8.0),
                                onPressed: (){
                                //what to do here ?
                              },),

                              ],
                          ),
                              
                            ],
                      ),
            ),
     swipeCompleteCallback: (CardSwipeOrientation orientation,int index){
      if (orientation == CardSwipeOrientation.LEFT){
            print("left");

          }
           
          if (orientation == CardSwipeOrientation.RIGHT){
            
            print("Right" );
            
          }
       }
            
    );

Add this above your build method:

CardController cardController = new CardController();

Then add the controller in your TinderSwapCard() widget:

TinderSwapCard(
  cardController: cardController,
)

Finally add this to your buttons:

RawMaterialButton(
  fillColor: Colors.white,
  child: Icon(Icons.delete, size: 50.0,color: Colors.red,),
  shape: CircleBorder(),
  padding: const EdgeInsets.all(8.0),
  onPressed: (){
    cardController.triggerLeft();
  },
),
RawMaterialButton(
  fillColor: Colors.white,
  child: Icon(Icons.thumb_up,size: 50.0,color: Colors.green,),
  shape: CircleBorder(),
  padding: const EdgeInsets.all(8.0),
  onPressed: (){
    cardController.triggerRight();
  },
),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM