简体   繁体   English

Flutter ListTile 前导图像和标题 alignment

[英]Flutter ListTile leading image and title alignment

In a standard ListTile, is it possible to align the leading image and the title to be at the top, levelled?在标准的 ListTile 中,是否可以将前导图像和标题对齐到顶部,水平对齐?

 child: ListTile(
    leading: FlutterLogo(size: 72.0),
    title: Text('Three-line ListTile'),
    subtitle: Text(
      'A sufficiently long subtitle warrants three lines.'
    ),
    trailing: Icon(Icons.more_vert),
    isThreeLine: true,
  ),

https://api.flutter.dev/flutter/material/ListTile-class.htmlhttps://api.flutter.dev/flutter/material/ListTile-class.html

I think you should consider using a Row widget as said in the documentation of the ListTile you should use a Row for example to achieve complex UIs.我认为您应该考虑使用ListTile 文档中所述的Row小部件,例如,您应该使用Row来实现复杂的 UI。 In your case you need a Row with property crossAxisAlignment: CrossAxisAlignment.start在您的情况下,您需要具有属性crossAxisAlignment: CrossAxisAlignment.startRow

Row(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: <Widget>[
      CircleAvatar(
        radius: 20,
        backgroundImage: AssetImage('assets/avatar1.jpg'),
      ),
      Expanded(
        child: Container(
          padding: EdgeInsets.only(left: 5),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              RichText(
                text: TextSpan(
                  style: DefaultTextStyle.of(context).style,
                  children: [
                    TextSpan(
                      text: 'hello :  ',
                      style: TextStyle(fontWeight: FontWeight.bold),
                    ),
                    TextSpan(
                      text:
                          'the comment comment the comment comment the comment comment comment comment the comment comment the comment comment',
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    ],
  ),

Use Transform try this使用变换试试这个

leading: Transform.translate(
              offset: Offset(0, -8),
              child: Container(
                height: 32,
                width: 32,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(6)),
                  color: ThemeColor.lightGrey,
                ),
                child: Icon(CupertinoIcons.person_fill),
              ),
            ),

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

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