【问题标题】:How change color index on Flutter. Hallo i want to change color on index with value ''einmal'如何在 Flutter 上更改颜色索引。你好,我想用值''einmal'改变索引的颜色
【发布时间】:2021-08-09 20:00:14
【问题描述】:

你好,我想用 value = 'einmal' 更改索引上的列表颜色

小部件 _buildChoice() { 返回容器( 高度:MediaQuery.of(context).size.height/4,

    child: ListView.builder(
        itemCount: _choices.length,
        itemBuilder: (BuildContext context, int index) {
          return  RaisedButton(
            child: new Text(_choices[index]),
            textColor: Colors.white,
            // 2
            color: _hasBeenPressed ? Colors.green : Colors.red,
            // 3
            onPressed: () => {
              setState(() {
                if(_choices[index] == 'einmal') {
                  _hasBeenPressed = !_hasBeenPressed;
                }
              })
            },
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(30.0)
            ),
          );


        }
    )
);}

【问题讨论】:

    标签: flutter


    【解决方案1】:
     color: _choices[index] == 'einmal' ? Colors.green : Colors.red,
    

    【讨论】:

      猜你喜欢
      • 2022-12-01
      • 1970-01-01
      • 2015-05-28
      • 2017-11-07
      • 2014-01-21
      • 2022-10-12
      • 2014-04-14
      • 1970-01-01
      • 2010-10-19
      相关资源
      最近更新 更多