116 lines
2.5 KiB
Dart
116 lines
2.5 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter_card_swiper/card_swiper.dart';
|
|
import 'package:example/example_candidate_model.dart';
|
|
import 'package:example/example_card.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'example_buttons.dart';
|
|
|
|
void main() {
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({
|
|
Key? key,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const CupertinoApp(
|
|
debugShowCheckedModeBanner: false,
|
|
home: Example(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class Example extends StatefulWidget {
|
|
const Example({
|
|
Key? key,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
State<Example> createState() => _ExamplePageState();
|
|
}
|
|
|
|
class _ExamplePageState extends State<Example> {
|
|
final CardSwiperController controller = CardSwiperController();
|
|
|
|
List<ExampleCard> cards = [];
|
|
|
|
@override
|
|
void initState() {
|
|
_loadCards();
|
|
super.initState();
|
|
}
|
|
|
|
void _loadCards() {
|
|
for (ExampleCandidateModel candidate in candidates) {
|
|
cards.add(
|
|
ExampleCard(
|
|
candidate: candidate,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CupertinoPageScaffold(
|
|
child: Column(
|
|
children: [
|
|
const SizedBox(
|
|
height: 50,
|
|
),
|
|
SizedBox(
|
|
height: MediaQuery.of(context).size.height * 0.75,
|
|
child: CardSwiper(
|
|
unlimitedUnswipe: true,
|
|
controller: controller,
|
|
unswipe: _unswipe,
|
|
cards: cards,
|
|
onSwipe: _swipe,
|
|
padding: const EdgeInsets.only(
|
|
left: 25,
|
|
right: 25,
|
|
top: 50,
|
|
bottom: 40,
|
|
),
|
|
),
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const SizedBox(
|
|
width: 80,
|
|
),
|
|
swipeLeftButton(controller),
|
|
const SizedBox(
|
|
width: 20,
|
|
),
|
|
swipeRightButton(controller),
|
|
const SizedBox(
|
|
width: 20,
|
|
),
|
|
unswipeButton(controller),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _swipe(int index, CardSwiperDirection direction) {
|
|
log("the card was swiped to the: " + direction.name);
|
|
}
|
|
|
|
void _unswipe(bool unswiped) {
|
|
if (unswiped) {
|
|
log("SUCCESS: card was unswiped");
|
|
} else {
|
|
log("FAIL: no card left to unswipe");
|
|
}
|
|
}
|
|
}
|