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 have a button build a widget and have it setstate

I currently have a InkWell that builds a custom widget alert dialog when pressed using the build method below.

InkWell(
  onTap: () => showDialog<String>(
    context: context,
    builder: (BuildContext context) => Popup(),

I also need it to set the state of some Bools and Int’s when pressed which usually happens when using the setstate method.
can someone please show me how to do both build a widget and setstate when the button is pressed?
what would the code look like?

cheers

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

>Solution :

Make a function and set bools before you build the dialog. Then call the method in onTap:

buildMyDialog(){
  myBool = false;
  myInt = 2;
  showDialog<String>(
    context: context,
    builder: (BuildContext context) => Popup(),
  );
}

If you need your current UI to use the values, setState before showing dialog in the same method.

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