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

时间:2019-04-12 10:00:00

标签: android user-interface dart flutter material-design

我正在创建一个应用程序内电子邮件收件箱,并希望在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;
              },
            )
        )
    );
  }

1 个答案:

答案 0 :(得分:2)

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