import 'package:example/example_candidate_model.dart'; import 'package:example/example_card.dart'; import 'package:flutter/material.dart'; import 'package:flutter_card_swiper/flutter_card_swiper.dart'; void main() { runApp( const MaterialApp( debugShowCheckedModeBanner: false, home: Example(), ), ); } class Example extends StatefulWidget { const Example({ Key? key, }) : super(key: key); @override State createState() => _ExamplePageState(); } class _ExamplePageState extends State { final CardSwiperController controller = CardSwiperController(); final cards = candidates.map((candidate) => ExampleCard(candidate)).toList(); @override Widget build(BuildContext context) { return Scaffold( body: SafeArea( child: Column( children: [ Flexible( child: CardSwiper( controller: controller, cardsCount: cards.length, numberOfCardsDisplayed: 3, onSwipe: _onSwipe, onUndo: _onUndo, padding: const EdgeInsets.all(24.0), cardBuilder: (context, index) => cards[index], ), ), Padding( padding: const EdgeInsets.all(16.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ FloatingActionButton( onPressed: controller.undo, child: const Icon(Icons.rotate_left), ), FloatingActionButton( onPressed: controller.swipe, child: const Icon(Icons.rotate_right), ), FloatingActionButton( onPressed: controller.swipeLeft, child: const Icon(Icons.keyboard_arrow_left), ), FloatingActionButton( onPressed: controller.swipeRight, child: const Icon(Icons.keyboard_arrow_right), ), FloatingActionButton( onPressed: controller.swipeTop, child: const Icon(Icons.keyboard_arrow_up), ), FloatingActionButton( onPressed: controller.swipeBottom, child: const Icon(Icons.keyboard_arrow_down), ), ], ), ), ], ), ), ); } bool _onSwipe( int previousIndex, int? currentIndex, CardSwiperDirection direction, ) { debugPrint( 'The card $previousIndex was swiped to the ${direction.name}. Now the card $currentIndex is on top', ); return true; } bool _onUndo( int? previousIndex, int currentIndex, CardSwiperDirection direction, ) { debugPrint( 'The card $currentIndex was undod from the ${direction.name}', ); return true; } }