简体   繁体   English

从外部更新 StatefulBuilder

[英]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.

相关问题 在 StatefulBuilder 小部件之外设置 StatefulBuilder state - Set StatefulBuilder state outside of StatefulBuilder widget Flutter DropdownButton 在 StatefulBuilder 中没有更新 - Flutter DropdownButton doesn't update in StatefulBuilder setState 在 StatefulBuilder 内部更新,但在使用外部方法时不更新 - setState updating inside StatefulBuilder but not updating when using a method outside 有没有办法为 Flutter StatefulBuilder 设置一个定期计时器,以每 1 秒用 setState() 更新一次? - Is there a way to set a periodic timer for a Flutter StatefulBuilder to update with setState() every 1 second? 如何使用 statefulBuilder 在对话框内使用 setState() 更新 Listview.builder 中的文本字段搜索 - How to make a Textfield search in Listview.builder update with setState() inside a Dialog using statefulBuilder 警报对话框中的值不会从外部更新 - values in alert dialog not update from outside StatefulBuilder与StatefulWidget - StatefulBuilder vs StatefulWidget Flutter 中的 StatefulBuilder VS StatefulWidget - 性能 - StatefulBuilder VS StatefulWidget in Flutter - performance Flutter - modalBottomSheet 中 StatefulBuilder 中的 TextField 不起作用 - Flutter - TextField in StatefulBuilder in modalBottomSheet not working 强制 navDrawer state 从外部更新 state scope - Force navDrawer state update from outside state scope
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM