Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set dynamic function to InkWell widget?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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,
              ),

I don't know why i am getting this

>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,
            ),
          ),
        ],
      ),
    ),
  ),
);

}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading