I have a List of inkwell in my app this inkwells each pushes a new page.if i press two of those items in my app it opens two new page. i want to avoid this. i want to disable onTap in my inkwells for sometime. how can i achieve that.
ListView.builder(
itemCount:
controller.supplierRequestDetails.length,
itemBuilder: (context, int index) {
return InkWell(
onTap:(){
Navigator.pushNamed(context, 'hello_page');
}
)
});
CodePudding user response:
Handle onTap like below:
bool isTap=false;
ListView.builder(
itemCount: controller.supplierRequestDetails.length,
itemBuilder: (context, int index) {
return InkWell(onTap: () async{
if(!isTap){
isTap = true;
await Navigator. pushNamed(context,'hello_page');
isTap = false;
}
},
);
)
CodePudding user response:
Wrap your Inkwell with IgnorePointer
In your case, if you are using any state management method you can ignore setState and use relatable.
bool isClicked = false; //Default false
IgnorePointer(
ignoring: isClicked,
child: InkWell(
onTap: () {
isClicked = true;
Future.delayed(const Duration(seconds: 2), () {
isClicked = false;
setState(() {});
});
print("CLICKED 123123123");
setState(() {});
},
child: Container(height :150, width: 150,color: Colors.amber)
),
),
CodePudding user response:
You Need to add child in inkwell to be clickable
ListView.builder(
itemCount:
controller.supplierRequestDetails.length,
itemBuilder: (context, int index) {
return InkWell(
/**-----> */ child:Text("$index"),
onTap:(){
Navigator.pushNamed(context, 'hello_page');
}
)
});