我已经编写了下面的代码,当用户想要的时候,可以让容器向左滑动.
import 'package:flutter/material.dart';
double swipH = 0 ;
double swipV = 0 ;
class App extends StatefulWidget {
const App({Key? key}) : super(key: key);
@override
State<App> createState() => _AppState();
}
class _AppState extends State<App> {
bool isV = true ;
bool isH = true ;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onLongPress: (){
debugPrint('vvvvvvvvv');
},
onPanUpdate:(noti){
if(noti.delta.dy < 0&&isV){
isH = false;
swipV += noti.delta.dy;
setState(() {});
}
if(noti.delta.dx < 0&&isH){
isV = false;
debugPrint('Started');
swipH += noti.delta.dx;
setState(() {});
}
},
onPanEnd:(noti){
isV = true ;
isH = true ;
swipH=0;
swipV = 0 ;
setState(() {});
},
child: Transform.translate(
offset: Offset(swipH, swipV),
child: Container(
padding: const EdgeInsets.all(8),
height: 200,
width: MediaQuery.of(context).size.width / 2,
color: Colors.red,
),
),
),
],
),
),
);
}
}
编辑
onLongPress: (){
debugPrint('onLongPress');
},
有什么好主意吗
不用onLongPress
.一切都很好..但我需要这个例子中逻辑相同的方法