【问题标题】:How to change the layout of List Tile on selection?如何在选择时更改列表拼贴的布局?
【发布时间】:2019-02-19 16:52:04
【问题描述】:

我有一个列表视图。如果选择了索引,我想更改平铺布局。类似image with ListTile Selected 和我开发的what i have able to achieve till now。选择 List Tile 布局后,应如第一个链接所示进行更改。

Widget _buildRow() {

 return

   Column(
    children: <Widget>[
      Divider(
        height: 35.0,
      ),
            ListTile(
              leading: new Text(
                "Set 1",
                style: TextStyle(
                  fontSize: 20.0,
                  color: Colors.black,
                  decoration: TextDecoration.none,
                  decorationStyle: TextDecorationStyle.double,
                  fontFamily: 'Raleway-Medium',
                ),
              ),
              title: Center(
                child: new Text(
                  "40 Lbs",
                  style: TextStyle(
                    fontSize: 18.0,
                    color: Colors.black,
                    decoration: TextDecoration.none,
                    decorationStyle: TextDecorationStyle.double,
                    fontFamily: 'Raleway-Medium',
                  ),
                ),
              ),
              trailing: IconButton(
                icon: (_isFavorited
                    ? Icon(Icons.check_circle)
                    : Icon(
                        Icons.check_circle_outline,
                        color: Colors.grey,
                      )),
                color: Colors.lightBlueAccent,
                iconSize: 35.0,
                splashColor: Colors.tealAccent,
                onPressed: _toggleFavorite,
              ),
            ),
      Stack(
       children: <Widget>[
         Padding(
           padding: const EdgeInsets.only(bottom:10.0),
           child: Divider(
             height: 40.0,
           ),
         ),
         Center(
           child: IconButton(
             icon: (_isFavorited
                 ? Icon(Icons.cancel)
                 : Icon(
               Icons.cancel,
               color: Colors.grey,
             )),
             color: Colors.lightBlueAccent,
             iconSize: 35.0,
             splashColor: Colors.tealAccent,
             onPressed: _resetSetData,
           ),
         ),

       ],
      ),

      ListTile(

              title: Center(
                child: new Text(
                  "10 reps",
                  style: TextStyle(
                    fontSize: 18.0,
                    color: Colors.black,
                    decoration: TextDecoration.none,
                    decorationStyle: TextDecorationStyle.double,
                    fontFamily: 'Raleway-Medium',
                  ),
                ),
              ),
            ),
    ],
  );
}

void _toggleFavorite() {
   setState(() {
    if (_isFavorited) {
     _isFavorited = false;
   } else {
     _isFavorited = true;
  }
});
}

void _resetSetData() {
  setState(() {
    if (_isFavorited) {
    _isFavorited = false;
  } else {
    _isFavorited = true;
  }
});
 }

实现此 UI 的最佳方式是什么?

【问题讨论】:

    标签: dart flutter flutter-layout


    【解决方案1】:

    使用容器包装列表图块,并使用 bool 来保持图块的状态,以便您可以更改列表图块的颜色。谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      相关资源
      最近更新 更多