如何从ListTile的leading属性中移除固有填充?如何填充leading属性容器的颜色?

3

我正在创建一个应用内电子邮件收件箱,并希望为ListTile中前导图标的背景着色。如何填充前导属性,以使图标上下有间距?

过去,我尝试将ListTile的contentpadding设置为0.0,以及将Container的padding设置为0.0。

请查看下面的代码:

    Widget buildItem(LeaveBehindItem item) {
    final ThemeData theme = Theme.of(context);
    return new Dismissible(
        key: new ObjectKey(item),
        direction: _dismissDirection,
        onDismissed: (DismissDirection direction) {
          setState(() {
            leaveBehindItems.remove(item);
          });
          final String action = (direction == DismissDirection.endToStart) ? 'archived' : 'deleted';
          _scaffoldKey.currentState.showSnackBar(new SnackBar(
              content: new Text('You $action item ${item.index}'),
              action: new SnackBarAction(
                  label: 'UNDO',
                  onPressed: () { handleUndo(item); }
              )
          ));
        },
        background: new Container(
            color: Colors.green,
            child: const ListTile(
                leading: const Icon(Icons.done, color: Colors.white, size: 36.0)
            )
        ),
        secondaryBackground: new Container(
            color: Colors.orange,
            child: const ListTile(
                trailing: const Icon(Icons.query_builder, color: Colors.white, size: 36.0)
            )
        ),
        child: new Container(
           padding: EdgeInsets.all(0.0),
            decoration: new BoxDecoration(
                color: theme.canvasColor,
                border: new Border(bottom: new BorderSide(color: theme.dividerColor))
            ),
            child: new ListTile(
              contentPadding: EdgeInsets.all(0.0),
              leading: Container(
                decoration: BoxDecoration(color: Colors.grey[500]),
                child: Icon(Icons.lightbulb_outline, size: 50.0,),
              ),
              title: new Text(item.name),
              subtitle: new Text('${item.subject}\n${item.to}\nHas been read: ${item.read}'),
              onTap: () async {
                await Navigator.push(context, MaterialPageRoute(builder: (context) => EmailBody(item: item)));
               item.read = true;
              },
            )
        )
    );
  }
1个回答

4

ListTile 的顶部和底部内边距都是硬编码的 4:

// The minimum padding on the top and bottom of the title and subtitle widgets.
static const double _minVerticalPadding = 4.0;

唯一的解决方法是用自定义行替换ListTile,这样将为您提供所需的所有灵活性。

另外,Padding设置为0不会对任何可视化效果产生影响。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接