Created
February 19, 2019 11:07
-
-
Save IshanFx/0a2f539d76c33ce66315156e0a26df19 to your computer and use it in GitHub Desktop.
Flutter Swipe Remove card(Tinder Like)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'MatchCard.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 Card Stack'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
List<Widget> cardList; | |
void _removeCard(index) { | |
setState(() { | |
cardList.removeAt(index); | |
}); | |
} | |
@override | |
void initState() { | |
// TODO: implement initState | |
super.initState(); | |
cardList = _getMatchCard(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Stack( | |
alignment: Alignment.center, | |
children: cardList, | |
), | |
), | |
); | |
} | |
List<Widget> _getMatchCard() { | |
List<MatchCard> cards = new List(); | |
cards.add(MatchCard(255, 0, 0, 10)); | |
cards.add(MatchCard(0, 255, 0, 20)); | |
cards.add(MatchCard(0, 0, 255, 30)); | |
List<Widget> cardList = new List(); | |
for (int x = 0; x < 3; x++) { | |
cardList.add(Positioned( | |
top: cards[x].margin, | |
child: Draggable( | |
onDragEnd: (drag){ | |
_removeCard(x); | |
}, | |
childWhenDragging: Container(), | |
feedback: Card( | |
elevation: 12, | |
color: Color.fromARGB(255, cards[x].redColor, cards[x].greenColor, cards[x].blueColor), | |
shape: | |
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), | |
child: Container( | |
width: 240, | |
height: 300, | |
), | |
), | |
child: Card( | |
elevation: 12, | |
color: Color.fromARGB(255, cards[x].redColor, cards[x].greenColor, cards[x].blueColor), | |
shape: | |
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), | |
child: Container( | |
width: 240, | |
height: 300, | |
), | |
), | |
), | |
)); | |
} | |
return cardList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment