How to disable a button for multiple click in flutter?

Issue

I am using List Tile for showing items on a list,on clicking on these i will call my Firebase function and some logic.but unable to find out any solution regarding how to stop user to multiple times clicking on single button,

because after clicking button response getting on some delay and i am unable to stop user for clicking.
i tried with other widget also like Inkwell and Gesture Detector,but unable to find solution.

ListTile(
  title: const Text("My List Text"),
  onTap: (){
_myFunction();//here i want to stop multiple times click
    }
  )

Solution

Just set a bool variable globally and check it every time, then change it on the first tap:

bool isTapped=false;

...

ListTile(
  title: const Text("My List Text"),
  onTap: (){
if(!isTapped){
isTapped=true;
_myFunction();
    }
}
  )

You can also change it to be clickable again after your function is complete.

Answered By – Mehrzad Mohammadi

Answer Checked By – Pedro (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *