I am trying to set up button, which has green color, when on long press and red, when it is released (back to initial state)
onLong press is working fine, but when I added onLongPress end I got error:
The argument type ‘void Function()’ can’t be assigned to the parameter type ‘void Function(LongPressEndDetails)?’.
Here is my code snippet:
GestureDetector(
onLongPress: () => setState(() {}),
onLongPressEnd: () => setState(() {}),
),
2
Answers
onLongPressEnd
providesLongPressEndDetails
on callback, you need to add param,or ignore like
As the error message says: The
onLongPressEnd
callback expects a function that also accepts the event details (LongPressEndDetails
).So your code should look like:
If you are not interested in the event details you can ignore them like this: