gpt4 book ai didi

flutter - IconButton 在 onPressed 期间调用 setState 显示没有链式 react

转载 作者:IT王子 更新时间:2023-10-29 06:50:17 29 4
gpt4 key购买 nike

在我的 IconButtononPressed 期间,我需要更新数据库,然后更新 UI,以便用户看到数据更改的反馈。为此,我调用了 setState,它成功地让 Widget 重建。问题是我不再看到触摸反馈链式 react ,因为 Widget 会立即重建。

var button = new IconButton(
icon: new Icon(isMyBoolTrue ? Icons.undo : Icons.event_available),
onPressed: () => setState(() => toggleDatabaseBool)
);

最佳答案

问题是我创建了一个 ObjectKey,其中包含一个在 build 期间每次都重新创建的对象。通过使用 ObjectKey 和我的对象的 id 字段而不是对象本身解决了这个问题。

不好

var card = new Card(
key: new ObjectKey(goal), //the goal object was re-created during `build`
child: button
);

var card = new Card(
key: new ObjectKey(goal.id), // need to key off of the id field as it remains constant
child: button
);

关于flutter - IconButton 在 onPressed 期间调用 setState 显示没有链式 react ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41404257/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com