Reputation: 17321
in flutter application i simple variable as currentValue
and this variable value should be between 0.0
and 1
, by gesture and swipe to right or left i want to change this value of currentValue
swipe to right should be add and swipe to left should be minus, considering latest value of variable, that means, for example:
swipe to right => 0.0, 0.1, 0.2, 0.3, 0.4 ...
swipe to left => 0.5, 0.4, 0.3, 0.2, 0.1 ...
Upvotes: 1
Views: 2820
Reputation: 4109
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;
});
}
},
),
),
)
],
),
);
}
}
https://stackoverflow.com/a/54238847/9142279
Upvotes: 4