Flutter卡片滑动插件swipe_deck的使用
Flutter卡片滑动插件swipe_deck的使用
Swipe Deck 是一个简单的Flutter包,用于模仿iMessage图像选择器的功能。它允许你将一组小部件以可滑动的方式展示。
当前功能
- 添加一组小部件以在可滑动的卡片组中展示。
- 基本的小部件自定义。
示例演示
使用方法
要使用这个插件,只需将你想要添加到卡片组中的小部件包裹在 SwipeDeck
小部件中:
import 'package:flutter/material.dart';
import 'package:swipe_deck/swipe_deck.dart';
const IMAGES = ["apex", "cod", "destiny", "fc3", "game_4", "ghost", "mk11", "nfs", "pubg", "mk112"];
final borderRadius = BorderRadius.circular(20.0);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Swipe Deck',
home: TestPage(),
);
}
}
class TestPage extends StatelessWidget {
const TestPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Swipe Deck"),
),
body: Center(
child: Container(
width: 600,
child: Center(
child: SwipeDeck(
startIndex: 3, // 设置初始显示的索引
emptyIndicator: Container(
child: Center(
child: Text("Nothing Here"),
),
),
cardSpreadInDegrees: 5, // 调整背景卡片的展开角度
onSwipeLeft: (){
print("USER SWIPED LEFT -> GOING TO NEXT WIDGET");
},
onSwipeRight: (){
print("USER SWIPED RIGHT -> GOING TO PREVIOUS WIDGET");
},
onChange: (index){
print(IMAGES[index]);
},
widgets: IMAGES.map((e) => GestureDetector(
onTap: () {
print(e);
},
child: ClipRRect(
borderRadius: borderRadius,
child: Image.asset(
"assets/images/$e.jpg",
fit: BoxFit.cover,
)),
))
.toList(),
),
),
),
),
);
}
}
主要参数说明
startIndex
: 初始显示的卡片索引。emptyIndicator
: 当没有卡片时显示的内容。cardSpreadInDegrees
: 控制背景卡片的展开角度。onSwipeLeft
: 用户向左滑动时触发的回调。onSwipeRight
: 用户向右滑动时触发的回调。onChange
: 每当卡片改变时触发的回调。widgets
: 需要展示的一组小部件。
社交链接
发现有用?
如果觉得这个插件有用,可以通过Buy Me A Coffee支持开发者。
许可证
此项目采用MIT许可证。
以上内容详细介绍了如何使用 `swipe_deck` 插件,并提供了一个完整的示例代码来帮助你快速上手。希望这些信息对你有所帮助!
更多关于Flutter卡片滑动插件swipe_deck的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复