I was creating a FireBase Signing using Google and Phone in Flutter and there required two button so i created a function and passed a function in a parameter to set on onTap for Inkwell which would work different for different passing functions but there is an error.
There is my button widget
Widget buttonItem(
String imagepath, String buttonName, double size, Function Tap) {
return InkWell(
onTap: Tap, //Here its showing error IDE not allowing
child: Container(
width: MediaQuery.of(context).size.width - 60,
height: 60,
child: Card(
color: Colors.black,
elevation: 8,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
side: BorderSide(width: 1, color: Colors.grey)),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
imagepath,
height: size,
width: size,
),
SizedBox(
width: 15,
),
Text(
buttonName,
style: TextStyle(
color: Colors.white,
fontSize: 17,
),
),
],
),
),
),
);
}
And here is the args passing.
buttonItem("assets/google.svg", "Continue with Google", 25,
() async {
await authClass.googleSignIn(context);
}),
SizedBox(
height: 15,
),
buttonItem("assets/phone.svg", "Continue with Phone", 25, () {}),
SizedBox(
height: 15,
),
>Solution :
Then just try to use this one
Widget buttonItem(
String imagepath, String buttonName, double size, void Function() Tap) {
return InkWell(
onTap: Tap, //Here its showing error IDE not allowing
child: Container(
width: MediaQuery.of(context).size.width - 60,
height: 60,
child: Card(
color: Colors.black,
elevation: 8,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
side: BorderSide(width: 1, color: Colors.grey)),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
imagepath,
height: size,
width: size,
),
SizedBox(
width: 15,
),
Text(
buttonName,
style: TextStyle(
color: Colors.white,
fontSize: 17,
),
),
],
),
),
),
);
}
