How to change the state of an entry in CustomMultiChildLayout in Flutter

*爱你&永不变心* 提交于 2019-12-13 03:22:45

问题


I used CustomMultiChildLayout to customize a layout, and implemented MultiChildLayoutDelegate. There are many entries in the layout. I want to change the state when I click on these items, similar to the normal and pressed state of Button in Android. The part of the code is as follows, but it has no effect. Thanks!

Build item widget:

Color _color = Colors.redAccent;
Widget _buildChild(int index) {
return LayoutId(
    id: '$childId$index',
    child: GestureDetector(
      onTapDown: (event) {
        setState(() {
          _color = Colors.blue;
        });
      },
      onTapUp: (event) {
        setState(() {
          _color = Colors.redAccent;
        });
      },
      child: Container(
        width: 80.0 + Random().nextInt(30),
        height: 40,
        color: _color,
      ),
    ));
}

来源:https://stackoverflow.com/questions/53994395/how-to-change-the-state-of-an-entry-in-custommultichildlayout-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!