ListTile中半径大于27的Flutter CircleAvatar变为椭圆

时间:2020-05-07 11:22:37

标签: flutter flutter-layout

我对此有疑问,我需要一个Radius为35的CircleAvatar,但是放置在ListTile中的27以上的任何圆环都会使其变成椭圆形,从而限制了高度。在上方的容器中,它可以正确显示Radius40。有什么想法吗?

           Card(
              elevation: 0,
              child: ListTile(
                leading: CircleAvatar(
                  radius: 27,
                  backgroundImage: AssetImage('images/sophia_hs.jpg'),
                ),
                title:
                Text("Sophia Daniels",
                  style: TextStyle(
                    fontFamily: 'Roboto',
                    color: Colors.black,
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                subtitle:
                Text("Casting Director",
                  style: TextStyle(
                    fontFamily: 'Roboto',
                    color: Colors.black,
                    fontSize: 16,
                    fontWeight: FontWeight.normal,
                  ),
                ),
              ),
            ),
            Container(
              height: 120,
              color: Color(0xffffd504),
              child: Center(
                child: ListTile(
                  leading: CircleAvatar(
                    radius: 40,
                    backgroundImage: AssetImage('images/sophia_hs.jpg'),
                  ),
                  dense: false,
                  title: Text("Sophia Daniels",
                    style: TextStyle(
                      fontFamily: 'Roboto',
                      color: Colors.black,
                      fontSize: 20,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  subtitle: Text("Casting Director",
                    style: TextStyle(
                      fontFamily: 'Roboto',
                      color: Colors.black,
                      fontSize: 16,
                      fontWeight: FontWeight.normal,
                    ),
                  ),
                ),
              ),
            ),

enter image description here

2 个答案:

答案 0 :(得分:0)

尝试编辑容器的高度,使其大于120。 您也可以尝试Image.Asset()从资产加载图像。他们具有根据图像大小调整图像的能力。

答案 1 :(得分:0)

作为一种解决方法,将半径大于27的“ CircleAvatar”和“ ListTile”包装成一行,如下所示:

Row(
          children: [
            CircleAvatar(
              radius: 32,
              backgroundImage: AssetImage('images/sophia_hs.jpg'),
            ),
            Flexible(
              child: ListTile(
                title: Text(
                  "Sophia Daniels",
                  style: TextStyle(
                    fontFamily: 'Roboto',
                    color: Colors.black,
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                subtitle: Text(
                  "Casting Director",
                  style: TextStyle(
                    fontFamily: 'Roboto',
                    color: Colors.black,
                    fontSize: 16,
                    fontWeight: FontWeight.normal,
                  ),
                ),
              ),
            ),
          ],
        ),

ListTile应该包含在Flexible中,以避免“ BoxConstraints强制无限宽度”错误。