skip to Main Content

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


  1. onLongPressEnd provides LongPressEndDetails on callback, you need to add param,

    onLongPressEnd: (details) {
      
    },
    

    or ignore like

    onLongPressEnd: (_) {
      
    },
    
    Login or Signup to reply.
  2. As the error message says: The onLongPressEnd callback expects a function that also accepts the event details (LongPressEndDetails).

    So your code should look like:

       ...
       onLongPressEnd: (details) => ...
       ...
    

    If you are not interested in the event details you can ignore them like this:

       onLongPressEnd: (_) => ...
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search