-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.dart
155 lines (146 loc) · 4.38 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import 'package:disposable_provider/disposable_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:hop_swipe_cards/hop_swipe_cards.dart';
import 'package:provider/provider.dart';
void main() {
runApp(Example());
}
class Example extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(),
home: ExampleHomePage.create(),
);
}
}
class ExampleHomePage extends StatefulWidget {
static Widget create() {
return DisposableProvider(
create: (context) => CardController(),
child: ExampleHomePage(),
);
}
@override
_ExampleHomePageState createState() => _ExampleHomePageState();
}
class _ExampleHomePageState extends State<ExampleHomePage>
with TickerProviderStateMixin {
List<String> images = [
"images/pic_one.jpg",
"images/pic_two.jpg",
"images/pic_three.jpg",
"images/pic_four.jpg",
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Align(
alignment: Alignment(0, 0.9),
child: Container(
height: 80,
width: double.infinity,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
CustomButton(
icon: Icons.repeat,
onTap: () {
context.read<CardController>().triggerRewind();
},
),
SizedBox(
width: 60,
),
CustomButton(
icon: Icons.close,
onTap: () {
context.read<CardController>().triggerLeftOnCard();
},
),
SizedBox(
width: 60,
),
CustomButton(
icon: Icons.favorite_border,
onTap: () {
context.read<CardController>().triggerRightOnCard();
},
),
],
),
),
),
Center(
child: Container(
height: MediaQuery.of(context).size.height * 0.6,
child: HopSwipeCards(
noMoreSwipeCardsLeft: Center(child: Text('No more users left')),
totalNum: images.length,
maxWidth: MediaQuery.of(context).size.width * 0.9,
maxHeight: MediaQuery.of(context).size.width * 0.9,
minWidth: MediaQuery.of(context).size.width * 0.8,
minHeight: MediaQuery.of(context).size.width * 0.8,
cardBuilder: (context, index, a, b) =>
_SingleCard(image: images[index]),
swipeCompleteCallback: (int index, direction) {
//direction gives the swipe direction after completion
},
cardController: context.watch(),
),
),
),
],
),
);
}
}
class _SingleCard extends StatelessWidget {
final String image;
const _SingleCard({Key key, @required this.image}) : super(key: key);
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(16),
child: Center(
child: Container(
height: MediaQuery.of(context).size.width * 0.9,
width: MediaQuery.of(context).size.width * 0.9,
decoration: BoxDecoration(),
child: Image.asset(
image,
fit: BoxFit.fill,
),
),
),
);
}
}
class CustomButton extends StatelessWidget {
const CustomButton({Key key, @required this.icon, @required this.onTap})
: super(key: key);
final IconData icon;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Container(
height: 80,
width: 80,
child: Icon(
icon,
size: 40,
),
decoration: BoxDecoration(
shape: BoxShape.circle, color: Colors.amberAccent.withOpacity(0.7)),
),
);
}
}