当旋转木马结束时,在旁边显示按钮。

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

When the carousel ends show button next to it

问题

当用户完成浏览轮播中的4张图片后,我想显示一个"查看更多"按钮,就像下面的图片一样。

(https://i.stack.imgur.com/A3haM.jpg)

我尝试添加另一个轮播幻灯片,并只放置按钮,但它看起来像一个卡片,不太合适,我只需要一点空间和这个按钮出现。

这是轮播的代码:

CarouselSlider(
  options: CarouselOptions(
    height: 200.0,
    enlargeCenterPage: true,
    aspectRatio: 16 / 9,
    autoPlayCurve: Curves.fastOutSlowIn,
    enableInfiniteScroll: false,
    autoPlayAnimationDuration: const Duration(milliseconds: 800),
    viewportFraction: 0.8,
    onPageChanged: (index, reason) {
      setState(() {
        _currentIndex = index;
      });
    },
  ),
  items: cardList.map((card) {
    return Builder(builder: (BuildContext context) {
      return Container(
        height: MediaQuery.of(context).size.height * 0.30,
        width: MediaQuery.of(context).size.width,
        child: Card(
          color: Colors.blueAccent,
          child: card,
        ),
      );
    });
  }).toList(),
)

请注意,按钮部分并未包含在您提供的代码段中,您可能需要额外添加按钮以实现您的需求。

英文:

When the user is done browsing the 4 images in the carousel i want to show a see more button like the image below.

(https://i.stack.imgur.com/A3haM.jpg)

I've tried adding another carousel slide and only putting the button in it but it looks like a card and it dosen't looks right i just need a little bit of space and this button to apear.

This is the carousel:

CarouselSlider(
          options: CarouselOptions(
            height: 200.0,
            enlargeCenterPage: true,
            aspectRatio: 16 / 9,
            autoPlayCurve: Curves.fastOutSlowIn,
            enableInfiniteScroll: false,
            autoPlayAnimationDuration: const Duration(milliseconds: 800),
            viewportFraction: 0.8,
            onPageChanged: (index, reason) {
              setState(() {
                _currentIndex = index;
              });
            },
          ),
          items: cardList.map((card) {
            return Builder(builder: (BuildContext context) {
              return Container(
                height: MediaQuery.of(context).size.height * 0.30,
                width: MediaQuery.of(context).size.width,
                child: Card(
                  color: Colors.blueAccent,
                  child: card,
                ),
              );
            });
          }).toList(),
        ),

答案1

得分: 1

这应该适用于您:

这应该适用于您:

    class HomePage extends StatefulWidget {
      const HomePage({Key? key}) : super(key: key);
    
      @override
      State<HomePage> createState() => _HomePageState();
    }
    
    class _HomePageState extends State<HomePage> {
    
      final CarouselController buttonCarouselController = CarouselController();
    
      final List list = ["a", "b", "c", "d", "e"];
    
      bool showNext = false;
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(
              backgroundColor: Colors.black,
            ),
            body: Stack(
              alignment: Alignment.bottomRight,
              children: [
                CarouselSlider.builder(
                    itemCount: list.length,
                    carouselController: buttonCarouselController,
                    options: CarouselOptions(
                      height: 200,
                      enlargeCenterPage: true,
                      aspectRatio: 16 / 9,
                      autoPlayCurve: Curves.fastOutSlowIn,
                      enableInfiniteScroll: false,
                      autoPlayAnimationDuration: const Duration(milliseconds: 800),
                      viewportFraction: 0.8,
                      onPageChanged: (index, reason) {
                        if(list[index] == list.last){
                          setState(() {
                            showNext = true;
                          });
                        }else{
                          if(showNext){
                            setState(() {
                              showNext = false;
                            });
                          }
                        }
                      },
                    ),
                    itemBuilder: (BuildContext context, int itemIndex, int pageViewIndex) {
                      return Container(
                        color: Colors.grey,
                        alignment: Alignment.center,
                        child: Text(list[itemIndex]),
                      );
                    }
                ),
                Visibility(
                  visible: showNext,
                  child: IconButton(
                    onPressed: (){
                      buttonCarouselController.jumpToPage(0);
                    },
                    icon: const Icon(Icons.arrow_forward,size: 30,),
                  ),
                ),
              ],
            )
        );
      }
    }

当旋转木马结束时,在旁边显示按钮。


<details>
<summary>英文:</summary>

This should work for you:

    class HomePage extends StatefulWidget {
      const HomePage({Key? key}) : super(key: key);
    
      @override
      State&lt;HomePage&gt; createState() =&gt; _HomePageState();
    }
    
    class _HomePageState extends State&lt;HomePage&gt; {
    
      final CarouselController buttonCarouselController = CarouselController();
    
      final List list = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;];
    
      bool showNext = false;
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(
              backgroundColor: Colors.black,
            ),
            body: Stack(
              alignment: Alignment.bottomRight,
              children: [
                CarouselSlider.builder(
                    itemCount: list.length,
                    carouselController: buttonCarouselController,
                    options: CarouselOptions(
                      height: 200,
                      enlargeCenterPage: true,
                      aspectRatio: 16 / 9,
                      autoPlayCurve: Curves.fastOutSlowIn,
                      enableInfiniteScroll: false,
                      autoPlayAnimationDuration: const Duration(milliseconds: 800),
                      viewportFraction: 0.8,
                      onPageChanged: (index, reason) {
                        if(list[index] == list.last){
                          setState(() {
                            showNext = true;
                          });
                        }else{
                          if(showNext){
                            setState(() {
                              showNext = false;
                            });
                          }
                        }
                      },
                    ),
                    itemBuilder: (BuildContext context, int itemIndex, int pageViewIndex) {
                      return Container(
                        color: Colors.grey,
                        alignment: Alignment.center,
                        child: Text(list[itemIndex]),
                      );
                    }
                ),
                Visibility(
                  visible: showNext,
                  child: IconButton(
                    onPressed: (){
                      buttonCarouselController.jumpToPage(0);
                    },
                    icon: const Icon(Icons.arrow_forward,size: 30,),
                  ),
                ),
              ],
            )
        );
      }
    }

[![Pic][1]][1]


  [1]: https://i.stack.imgur.com/IwS4y.png

</details>



huangapple
  • 本文由 发表于 2023年4月20日 01:13:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76057190.html
匿名

发表评论

匿名网友

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

确定