Home > database >  I’m trying to pass a function into the onTap property in flutter and it just showing a red line unde
I’m trying to pass a function into the onTap property in flutter and it just showing a red line unde

Time:12-22

here's a screenshot of the codeenter image description here

I tried calling the function onPress in GestureDetector property onTap then no errors were showing then this was what i saw on the android emulator

CodePudding user response:

Change final Function onPress; to final void Function() onPress; or final VoidCallback onPress;, both are the same.

Then you can call the function inside widget as onTap: onPress.

CodePudding user response:

here is an exemple of how you can use onTap try soemthing like this probably you won't have a problem.

Future<void> _showSelectionDialog(BuildContext context) {
    return showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
              title: Text("From where do you want to take the photo?"),
              content: SingleChildScrollView(
                child: ListBody(
                  children: <Widget>[
                    GestureDetector(
                      child: Text("Gallery"),
                      onTap: () {
                        _openImagePicker(ImageSource.gallery);
                      },
                    ),
                    Padding(padding: EdgeInsets.all(8.0)),
                    GestureDetector(
                      child: Text("Camera"),
                      onTap: () {
                        takePhoto(ImageSource.camera);
                      },
                    )
                  ],
                ),
              ));
        });
  }
  • Related