[英]update StatefulBuilder from outside
I try to update a StatefulBuilder state form a showDialog, but I only can call the _setstate1 inside the StatefulBuilder.我尝试从 showDialog 更新 StatefulBuilder state,但我只能在 StatefulBuilder 中调用 _setstate1。 Is there a way to call _setstate1 from outside
有没有办法从外面调用_setstate1
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:这个 showDialog 小部件应该执行更新:
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我通过使用 ValueListenableBuilder 解决了它
can you explain more what are you trying to achieve?你能解释更多你想要达到的目标吗? and in what way the dialog is connected to the
updateMe()
function?对话框以何种方式连接到
updateMe()
function? it's a bit vague to be honest.说实话有点含糊。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.