在flutter应用程序中,我将简单变量设置为currentValue
,并且此变量值应介于0.0
和1
之间,通过手势并向右或向左滑动,我想更改此{ {1}}
向右滑动,向左滑动为负,例如:
currentValue
答案 0 :(得分:1)
class MyClass extends StatefulWidget {
@override
_MyClassState createState() => _MyClassState();
}
class _MyClassState extends State<MyClass> {
double value ;
@override
void initState() {
value = 0.0;
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
Expanded(child: Text('value = $value')),
Expanded(
child: Container(
color: Colors.red,
child: GestureDetector(
onPanUpdate:(DragUpdateDetails details){
if(details.delta.dx>0){
print('right swipe');
//right scroll
//increment counter
setState(() {
value+=0.1;
});
}
else if(details.delta.dx<0){
print('left swipe');
//left scroll
//decrement counter
setState(() {
value-=0.1;
});
}
},
),
),
)
],
),
);
}
}