2

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

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

2 回答 2

3

问题是我正在创建一个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
);
于 2016-12-31T10:17:17.707 回答
1

这不应该阻止飞溅。飞溅应该停止的唯一原因是,如果您在 IconButton 和材质之间添加或删除小部件之一,或更改其键,或更改材质的键,或在树中移动材质。(其中一些是目前框架中的错误,我希望在未来几个月内修复它们。)

您可以发布一个显示问题的最小应用程序吗?

同时,我们正在https://github.com/flutter/flutter/issues/6751https://github.com/flutter/flutter/issues/5456跟踪问题

于 2016-12-31T03:55:08.273 回答