How to change the state of an entry in CustomMulti

2019-08-20 10:35发布

问题:

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,
      ),
    ));
}