Search code examples
flutterdartflutter-layout

FloatingActionButton onLongPress listener in Flutter


I need to have a secondary action to be performed during the long press of my FloatingActionButton in my app.

floatingActionButton: FloatingActionButton(
  onPressed: someFunction,
  child: Icon(Icons.add),
  onLongPressed: //Something like this or any other solution
),

Solution

  • I'd suggest to use InkWell so that you can also have ripple effect.

    Here is how you can use it.

    floatingActionButton: InkWell(
      splashColor: Colors.blue,
      onLongPress: () {
        // handle your long press functionality here
      },
      child: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: someFunction,
      ),
    )