如何在Flutter的转盘滑块中增加图像的宽度和高度,而又不给carouselSlider设置高度

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

我需要构建一个轮播幻灯片,并在其下方放置一个图像和文本,并且图像约束必须为250 x250。我将图像和文本放在一列内,但是它们被截断并说在其中存在溢出底端。如果我给CarouselSlider小部件一个高度,它会起作用,但是我不应该这样做,因为文本会变化并且给出一个高度将不会保持一致。尝试了其他几种方法,例如Wrap,Expanded,但似乎都不起作用

这就是我的做法::

final List<String> imgList = [
  'https://images.unsplash.com/photo-1520342868574-5fa3804e551c?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=6ff92caffcdd63681a35134a6770ed3b&auto=format&fit=crop&w=1951&q=80',
  'https://images.unsplash.com/photo-1522205408450-add114ad53fe?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=368f45b0888aeb0b7b08e3a1084d3ede&auto=format&fit=crop&w=1950&q=80',

];

  Widget build(BuildContext context) {
    return Container(
       child: CarouselSlider(
          //height: 350,   //giving this a height fixes it but I shouldn't be doing it
          items: imgList.map((i) {
           return 
                Column(
                  children: [
                    Container(
                     margin: EdgeInsets.symmetric(horizontal: 5.0),
                      child: ClipRRect(
                         borderRadius: BorderRadius.circular(16.0),
                         child: Image.network(i,  height: 250, width: 250)),
                    ),
                    Text(i)
                  ],
                );

          }).toList(),
          viewportFraction: 1.0,
      )

image flutter carousel
1个回答
0
投票

具有FittedBox的包装容器和具有Flexible的包装具有不同的效果您可以查看演示图片并在您的情况下使用

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