我使用了swipe_cards包来实现像swipe这样的tinder,但我无法添加在左侧、右侧和顶部滑动时出现的文本小部件(不喜欢,喜欢和超级喜欢)。
class DatingAppDesign extends StatefulWidget {
@override
_DatingAppDesignState createState() => _DatingAppDesignState();
}
class _DatingAppDesignState extends State<DatingAppDesign> {
List<SwipeItem> _swipeItems = [];
late MatchEngine _matchEngine;
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
List<String> _names = ["1", "2", "3", "4", "last"];
List<Color> _colors = [
Colors.red,
Colors.blue,
Colors.green,
Colors.yellow,
Colors.orange
];
@override
void initState() {
for (int i = 0; i < _names.length; i++) {
_swipeItems.add(SwipeItem(
content: Content(text: _names[i], color: _colors[i]),
likeAction: () {
},
nopeAction: () {
},
superlikeAction: () {
}));
}
_matchEngine = MatchEngine(swipeItems: _swipeItems,);
super.initState();
}
@override
Widget build(BuildContext context) {
double ha = MediaQuery.of(context).size.height -
138 -
MediaQuery.of(context).padding.top;
return Scaffold(
body: Container(
height: ha,
width: double.infinity,
color: Colors.white,
child: Column(
children: [
Container(
decoration: BoxDecoration(
// color: Colors.white,
borderRadius: BorderRadius.vertical(
top: Radius.circular(35.0),
),
),
width: MediaQuery.of(context).size.width*0.8,
height: ha*0.7,
child: Center(
child: SwipeCards(
matchEngine: _matchEngine,
itemBuilder: (BuildContext context, int index) {
return Stack(children: [
Container(
alignment: Alignment.center,
color: _swipeItems[index].content.color,
child: Text(
_swipeItems[index].content.text,
style: TextStyle(fontSize: 100),
),
),
Center(child: Text("Hello World"),),
],
);
},
onStackFinished: () {
},
),
),
),
Container(
height: ha * 0.3,
child: Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
padding: EdgeInsets.all(1),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey,
//offset: Offset(0.0, 1.0), //(x,y)
blurRadius: 10.0,
),
],
color: Colors.white,
borderRadius: BorderRadius.circular(39),
),
constraints: BoxConstraints(maxHeight: 78, minWidth: 78),
child: Center(
child: SvgPicture.asset(
'assets/icons/cross.svg',
// color: Colors.white12,
),
),
),
Container(
padding: EdgeInsets.all(1),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey,
// offset: Offset(0.0, 1.0), //(x,y)
blurRadius: 10.0,
),
],
color: Colors.red,
borderRadius: BorderRadius.circular(49.5),
),
constraints: BoxConstraints(maxHeight: 99, minWidth: 99),
child: Center(
child: SvgPicture.asset(
'assets/icons/heart.svg',
// color: Colors.white12,
),
),
),
Container(
padding: EdgeInsets.all(1),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey,
// offset: Offset(0.0, 1.0), //(x,y)
blurRadius: 10.0,
),
],
color: Colors.white,
borderRadius: BorderRadius.circular(39),
),
constraints: BoxConstraints(maxHeight: 78, minWidth: 78),
child: Center(
child: SvgPicture.asset(
'assets/icons/star.svg',
// color: Colors.white12,
),
),
),
],
),
),
],
),
),
appBar: appbar,
bottomNavigationBar: BottomNevigationDesign(),
);
}
}我使用了手势检测器,但它不起作用。我读到了swipe_cards下的所有事件都使用了pub.dev上的相同示例。我完全卡住了,请帮帮我,谢谢。
发布于 2021-08-19 13:17:47
根据你的评论,我认为你正在寻找flutter中的snackbar。
https://stackoverflow.com/questions/68846656
复制相似问题