在 SizedBox 中居中一行 - Flutter

问题描述 投票:0回答:2

我想在我的应用程序中制作一个滑动面板。像这样:

现在我做了这个:

使用此代码:

SizedBox(
  width: 100.w,
  child: Align(
    alignment: Alignment.center,
    child: Stack(
      children: [
        SizedBox(
          height: 10.h,
          width: 100.w,
          child: ClipRRect(
            borderRadius: BorderRadius.circular(20),
            child: Image.network(
              'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR6j6N8zf-hAETioY1MLsCY_bnydJykgijQog&usqp=CAU',
              fit: BoxFit.cover,
            ),
          ),
        ),
        Container(
            padding: EdgeInsets.all(5.h),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10),
                gradient: LinearGradient(
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter,
                  colors: <Color>[
                    Colors.black.withAlpha(0),
                    Colors.black45,
                    Colors.black54
                  ],
                ))),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            IconButton(
                onPressed: () {}, icon: const Icon(Icons.arrow_back_ios)),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                const Text('TITRE'),
                SizedBox(
                  width: 60.w,
                  child: const Text(
                    'Contenu très trèstrèstrèstrèstrèstrèstrèstrèstrèstrèstrèstrèstrèstrèstrèstrèstrèstrèstrèstrès long',
                    overflow: TextOverflow.visible,
                  ),
                ),
              ],
            ),
            const Spacer(),
            IconButton(
                onPressed: () {}, icon: const Icon(Icons.arrow_forward_ios))
          ],
        )
      ],
    ),
  ),
);

我尝试了很多东西,所以我的代码可能有点混乱抱歉!

所以我的问题是我想把行居中。

有什么想法吗?或者也许有一些包裹可以帮助我处理这个面板?

flutter dart row center
2个回答
1
投票

getwidget 具有轮播功能并且有很好的文档记录:

https://docs.getwidget.dev/gf-carousel/


0
投票

好的,稍等片刻。 我的问题只是我想将行居中,但实际上我需要将列居中。 刚刚将

mainAxisAlignment: MainAxisAlignment.center
添加到行内的列中!

© www.soinside.com 2019 - 2024. All rights reserved.