I’m working on a Flutter project and I’m trying to implement swipe card functionality similar to Tinder or a deck of cards. I want users to be able to swipe left or right on cards, triggering actions based on the direction of the swipe.
I’ve explored some packages like flutter_swipe_cards, but I’m having trouble integrating them or customizing the behavior to suit my specific needs.
Could someone provide guidance or a code example on how to achieve this swipe card functionality in Flutter? I’d appreciate any advice, code snippets, or recommended packages to make this feature work smoothly in my app.
// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:swipe_card_demo/widget/colors.dart';
import 'package:swipe_card_demo/widget/text_widget.dart';
import '../controllers/home_controller.dart';
class HomeView extends GetView<HomeController> {
const HomeView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: AppColors.backgroundColor,
body: Padding(
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 16),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
InkWell(
onTap: () => Get.back(),
child: Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
border: Border.all(width: 1, color: Colors.grey)),
child: Center(
child: Image.asset(
"assets/icon/notification-icon.png",
height: 30)),
),
),
SizedBox(width: 15),
InkWell(
onTap: () => Get.back(),
child: Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
border: Border.all(width: 1, color: Colors.grey)),
child: Center(
child: Image.asset("assets/icon/home-icon.png",
height: 30)),
),
),
],
),
SizedBox(height: 20),
Container(
height: MediaQuery.of(context).size.height * 0.55,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.amber),
child: GestureDetector(
child: Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Image.asset(
"assets/icon/person.jpg",
fit: BoxFit.cover,
width: double.infinity,
),
),
Positioned(
right: 0,
child: IconButton(
onPressed: () {},
icon: Icon(
Icons.more_vert,
color: AppColors.whiteColor,
size: 40,
))),
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: MediaQuery.of(context).size.height * 0.095,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(15),
bottomLeft: Radius.circular(15)),
color: Colors.black.withOpacity(0.8)),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 24, vertical: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CommonTextWidget(
"szabo viktor",
color: AppColors.whiteColor,
fontSize: 26,
fontWeight: FontWeight.bold,
),
Row(
children: [
CommonTextWidget(
"Professional Model",
color: AppColors.whiteColor,
fontSize: 18,
fontWeight: FontWeight.bold,
),
SizedBox(
height: 25,
child: VerticalDivider(
color: AppColors.whiteColor,
thickness: 2,
),
),
CommonTextWidget(
"26",
color: AppColors.whiteColor,
fontSize: 18,
fontWeight: FontWeight.bold,
),
],
)
],
),
),
),
),
],
),
),
),
SizedBox(height: 20),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset("assets/icon/close-icon.png", height: 70),
SizedBox(width: 15),
Image.asset("assets/icon/heart-icon.png", height: 90),
SizedBox(width: 15),
Image.asset("assets/icon/fevorite-icon.png", height: 70)
],
)
],
),
)),
);
}
}
import 'package:get/get.dart';
class HomeController extends GetxController {
List swipeItems = [
{
'name': 'Michell',
'age': '24',
'imagePath': 'assets/background_images/szabo-viktor.jpg'
},
{
'name': 'Ryan',
'age': '26',
'imagePath': 'assets/background_images/ryan-jacobson.jpg'
},
{
'name': 'Daria',
'age': '25',
'imagePath': 'assets/background_images/the-paris.jpg'
}
];
}`
2
Answers
can you use this, it works fine:
kindly let me know if this helps.
you can try https://pub.dev/packages/flutter_card_swiper