Home > Net >  not able to make ontap function due to The argument type 'Function' can't be assigned
not able to make ontap function due to The argument type 'Function' can't be assigned

Time:10-27

Cannot make onTap function due to The argument type 'Function' can't be assigned to the parameter type 'void Function() So frustrating i was following a video and he successfully created the function but i am seeing this error

CodePudding user response:

Try below code hope its helpful to you. set onTap function like below. refer InkWell class here

InkWell(
      onTap: () {
        //write your onTap void function here
        print('Pressed');
      },
      child:Container(),//or your widget here
    ),

CodePudding user response:

The tip is the question mark. You have

void Function()?

onTap needs a not-nullable value:

void Function()

You need to wrap the function variable:

onTap : onTap!

or to prevent a crash you can just give an empty function to call when onTap is null:

onTap : onTap ?? (){}
  • Related