轮播滑块图像在Flutter中未正确获取宽度。

huangapple go评论53阅读模式
英文:

Carousal slider image is not taking width properly in flutter

问题

以下是翻译好的代码部分:

CarouselSlider(
  options: CarouselOptions(
    onPageChanged: (index, reason) {
      setState(() {
        _current = index;
      });
    },
    autoPlayAnimationDuration: Duration(seconds: 1),
    autoPlayCurve: Curves.easeInOut,
    autoPlay: true,
  ),
  items: images.map((i) {
    return PageView(
      controller: controller,
      physics: BouncingScrollPhysics(),
      children: [
        Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(15),
          ),
          child: Image.asset(i, fit: BoxFit.fitWidth, width: 350),
        ),
      ],
    );
  }).toList(),
),

请注意,我只翻译了代码部分,没有包括注释或其他内容。

英文:

I want like this

轮播滑块图像在Flutter中未正确获取宽度。

And I got this

轮播滑块图像在Flutter中未正确获取宽度。

            CarouselSlider(
              options: CarouselOptions(
              onPageChanged: (index, reason) {
                      setState(() {
                      _current = index;
                      });},

                autoPlayAnimationDuration:Duration(seconds: 1),
                autoPlayCurve: Curves.easeInOut,
                autoPlay: true,
                // height: 200,
                // initialPage: 0,
                // enlargeCenterPage: true,
              ),
              items: images.map((i) {
                return PageView(
                  controller: controller,
                  physics: BouncingScrollPhysics(),
                  children: [
                    Container(
                       // margin: EdgeInsets.symmetric(horizontal: 10.0),


                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(15),
                          // image: DecorationImage(
                          //     image:AssetImage(i),
                          //     fit: BoxFit.fill,
                          // ),
                        ),
                      child: Image.asset(i,fit: BoxFit.fitWidth, width: 350),
                    ),
                  ]
                );
              }).toList(),

            ),

答案1

得分: 0

你可以通过在CarouselOptions内使用viewportFraction: 1.0来修复它。

英文:

you can fix it by using viewportFraction: 1.0, inside the CarouselOptions

huangapple
  • 本文由 发表于 2023年7月6日 18:25:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76627857.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定