-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.dart
103 lines (95 loc) · 3.14 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import 'package:example/card_view.dart';
import 'package:flutter/material.dart';
import 'package:swipeable_card_stack/swipeable_card_stack.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int counter = 4;
@override
Widget build(BuildContext context) {
//create a CardController
SwipeableCardSectionController _cardController =
SwipeableCardSectionController();
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SwipeableCardsSection(
cardController: _cardController,
context: context,
//add the first 3 cards
items: [
CardView(text: "First card"),
CardView(text: "Second card"),
CardView(text: "Third card"),
],
onCardSwiped: (dir, index, widget) {
//Add the next card
if (counter <= 20) {
_cardController.addItem(CardView(text: "Card $counter"));
counter++;
}
if (dir == Direction.left) {
print('onDisliked ${(widget as CardView).text} $index');
} else if (dir == Direction.right) {
print('onLiked ${(widget as CardView).text} $index');
} else if (dir == Direction.up) {
print('onUp ${(widget as CardView).text} $index');
} else if (dir == Direction.down) {
print('onDown ${(widget as CardView).text} $index');
}
},
enableSwipeUp: true,
enableSwipeDown: true,
),
Container(
margin: EdgeInsets.symmetric(vertical: 20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FloatingActionButton(
child: Icon(Icons.chevron_left),
onPressed: () => _cardController.triggerSwipeLeft(),
),
FloatingActionButton(
child: Icon(Icons.chevron_right),
onPressed: () => _cardController.triggerSwipeRight(),
),
FloatingActionButton(
child: Icon(Icons.arrow_upward),
onPressed: () => _cardController.triggerSwipeUp(),
),
FloatingActionButton(
child: Icon(Icons.arrow_downward),
onPressed: () => _cardController.triggerSwipeDown(),
),
],
),
)
],
),
);
}
}