flutter 如何在Container中垂直对齐ListTile

uujelgoq  于 2023-02-25  发布在  Flutter
关注(0)|答案(1)|浏览(200)

我想把ListTile垂直对齐在容器的中间。水平对齐时,它应该保持左对齐。
我现在得到的是:

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Expanded Column Sample'),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 15),
              child: InkWell(
                onTap: () {
                },
                child: Container(
                    height: 35,
                    width: double.infinity,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(8.0),
                      gradient: const LinearGradient(
                          begin: Alignment.topCenter,
                          end: Alignment.bottomCenter,
                          colors: [Color(0xFFfe4a32), Color(0xFFcf1502)],),
                    ),
                    child: ListTile(
                      title: const Text(
                        "Some text",
                        style: TextStyle(
                            fontSize: 15.0,
                            color: Color(0xFFfe4a32),
                            fontWeight: FontWeight.w500),
                      ),
                      trailing: 
                         const Icon(
                          Icons.arrow_drop_down_outlined,
                          color: Color(0xFFfe4a32),
                          size: 35,
                        ),
                      
                    )),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
e0bqpujr

e0bqpujr1#

只移除容器的height。它会为你完成这项工作。但是如果你还想降低当前Container的高度,把dense:truecontentPadding: EdgeInsets.zero放在ListTile里面,沿着移除Containerheight
或者,如果您对以上输出不满意,您应该尝试使用RowColumn创建类似ListTile的小部件。

相关问题