繁体   English   中英

如何从ListTile主要属性中删除固有填充? 填充主属性容器的颜色

[英]How to remove inherent padding from ListTile leading property? Fill color of leading property container

我正在创建一个应用程序内电子邮件收件箱,并希望在ListTile中对前导图标的背景进行着色。 如何填充主属性,以便在图标上方和下方有填充?

在过去,我曾尝试将ListTile的contentpadding设置为0.0。 并将“容器填充”设置为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;
              },
            )
        )
    );
  }

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时将永远不会在视觉上改变任何内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM