如何在Flutter中的Positioned小部件内对齐文本?

3

我希望在LinearGradient容器中将文本对齐到左下角,就像图片中一样。但是,由于我将列部件作为容器的子项放置,因此它会居中显示。那么,我需要编辑哪些正确的代码才能获得图片中的结果。

enter image description here enter image description here

main.dart

SingleChildScrollView(
                scrollDirection: Axis.horizontal,
                child: Row(
                  children: <Widget>[
                    Container(
                      width: 300,
                      height: 220,
                      child: Stack(
                        fit: StackFit.expand,
                        children: <Widget>[
                          Image(
                            fit: BoxFit.cover,
                            image: AssetImage('assets/image1.png'),
                          ),
                          Positioned(
                            left: 0,
                            bottom: 0,
                            child: Container(
                              width: 285,
                              height: 110,
                              margin: EdgeInsets.only(left:8, bottom: 30),
                              padding: EdgeInsets.only(),
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(16),
                                  gradient: LinearGradient(
                                    begin: FractionalOffset.center,
                                    end: FractionalOffset.bottomCenter,
                                    colors: [
                                      const Color(0XFF000000).withOpacity(.0),
                                      const Color(0XFF000000).withOpacity(0.8),
                                    ],
                                  )
                              ),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  Text(
                                    "Jerusalem",
                                    style: TextStyle(
                                        fontFamily: 'AirbnbCerealBold',
                                        fontSize: 28,
                                        fontWeight: FontWeight.bold,
                                        color: Colors.white),
                                  ),
                                  Text(
                                    "1,243 Place",
                                    style: TextStyle(
                                        fontFamily: 'AirbnbCerealBook',
                                        fontSize: 14,
                                        color: Colors.white),
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
1个回答

4

你尝试过使用

mainAxisAlignment: MainAxisAlignment.end,

和Column一起吗?

child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,

它有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接