简体   繁体   中英

update StatefulBuilder from outside

I try to update a StatefulBuilder state form a showDialog, but I only can call the _setstate1 inside the StatefulBuilder. Is there a way to call _setstate1 from outside

this widget should be updated:

String image= "assets/images/1.png";

      Widget updateMe(){
        return StatefulBuilder(builder: (_context, _setState1) {
          return Image.asset(image);
        });
      }

this showDialog widget should execute the update:

  updateTheImage() {
    return showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
          content: Container(child: InkWell(
            onTap: () {
              _setState1(() {
                String image= "assets/images/2.png";
              });
            },
            child: Icon(Icons.check),
          ),)
          );}
        );
}

thanks

I solved it by using ValueListenableBuilder

can you explain more what are you trying to achieve? and in what way the dialog is connected to the updateMe() function? it's a bit vague to be honest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM