1

I want to build a swiper. And then limit its height and width. Code like this.

Container(
        height: 150,
        width: 350,
        child: Swiper(
          itemBuilder: (BuildContext context, int index) {
            return new Image.network(
              "http://via.placeholder.com/350x150",
              fit: BoxFit.fill,
            );
          },
          itemCount: 3,
          pagination: SwiperPagination(),
          control: SwiperControl(),
        ),
      );

In this case, the final render view will be like this.

enter image description here

And I find out if I use a Center widget wrap the Container widget that will work.

Center(child: Container(
        height: 150,
        width: 350,
        child: Swiper(
          itemBuilder: (BuildContext context, int index) {
            return new Image.network(
              "http://via.placeholder.com/350x150",
              fit: BoxFit.fill,
            );
          },
          itemCount: 3,
          pagination: SwiperPagination(),
          control: SwiperControl(),
        ),
      ),) 

enter image description here

Coco
  • 457
  • 1
  • 3
  • 14

1 Answers1

1

This is because parent witget has no idea how to align its child you should use Align widget