import 'package:flutter/material.dart';
import 'package:swipe_cards/draggable_card.dart';
import 'package:swipe_cards/swipe_cards.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final List<SwipeItem> _swipeItems = [];
late MatchEngine _matchEngine;
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
List<String> images = [
"https://media.istockphoto.com/photos/young-beautiful-woman-picture-id1294339577?b=1&k=20&m=1294339577&s=170667a&w=0&h=_5-SM0Dmhb1fhRdz64lOUJMy8oic51GB_2_IPlhCCnU=",
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSHZmgTTTZhXAoNOiDirLHYLSTieoUrSsZFnnmyCDPs_8_KLtgbpXWdEI9AL2yiqWEvaP4&usqp=CAU",
"https://image.shutterstock.com/image-photo/bowl-buddha-buckwheat-pumpkin-chicken-260nw-1259570605.jpg",
"https://images.unsplash.com/photo-1543353071-873f17a7a088?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8Zm9vZCUyMHByZXNlbnRhdGlvbnxlbnwwfHwwfHw%3D&w=1000&q=80",
"https://image.shutterstock.com/image-photo/food-photography-260nw-578546905.jpg"
];
@override
void initState() {
for (int i = 0; i < images.length; i++) {
_swipeItems.add(SwipeItem(
content: images[i],
likeAction: () {
},
nopeAction: () {
},
superlikeAction: () {
},
onSlideUpdate: (SlideRegion? region) async {
print("Region $region");
}
));
_matchEngine = MatchEngine(swipeItems: _swipeItems);
}
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
backgroudCurve(),
cardView(),
],
),
);
}
Widget backgroudCurve() {
return Container(
height: 350,
width: MediaQuery
.of(context)
.size
.width,
decoration: const ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(75),
bottomRight: Radius.circular(75),
)
),
gradient: LinearGradient(
colors: <Color>[
Color(0xFFFD0E42),
Color(0xFFC30F31),
],
)
),
child: const Padding(
padding: EdgeInsets.only(top: 50, left: 20.0),
child: Text("Explore", style: TextStyle(
fontSize: 22, color: Colors.white, fontWeight: FontWeight.bold),),
),
);
}
Widget cardView() {
return Center(
child: SizedBox(
height: MediaQuery
.of(context)
.size
.height / 1.5 - 100,
width: MediaQuery
.of(context)
.size
.width / 1.5,
child: SwipeCards(
itemBuilder: (BuildContext context, int index) {
return ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.network(
images[index], fit: BoxFit.fill,
)
);
},
onStackFinished: () {
_scaffoldKey.currentState?.showSnackBar(const SnackBar(
content: Text("Stack Finished"),
duration: Duration(milliseconds: 500),
));
},
matchEngine: _matchEngine,)
),
);
}
}
Be the first to comment.