的数据
我正在做一个Flutter项目,我正在尝试实现类似于Tinder或一副卡片的刷卡功能。我希望用户能够在卡片上向左或向右滑动,根据滑动方向触发操作。
我已经探索了一些包,如flutter_swipe_cards,但我在集成它们或定制行为以满足我的特定需求时遇到了麻烦。
有人能提供指导或代码示例,说明如何在Flutter中实现此刷卡功能吗?我非常感谢任何建议,代码片段或推荐包,以使此功能在我的应用程序中顺利工作。
// 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条答案
按热度按时间yyhrrdl81#
你能用这个吗,它工作得很好:
字符串
请让我知道这是否有帮助。
ccgok5k52#
你可以试试https://pub.dev/packages/flutter_card_swiper
字符串