自动播放旋转木马滑块

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

我正在尝试制作带有旋转木马滑块的应用程序,但是当我启用自动播放功能时,自动播放功能无法正常工作

我的应用程序在正文顶部包含一个轮播滑块,在应用程序的其余部分包含另一个按钮

所以我把旋转木马滑块放在容器内,因为它的孩子是一个列

并插入我的轮播滑块和页面小部件的其余部分

任何让它自动播放的解决方案?

class AdminContentState extends State<AdminContent> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          CarouselSlider(
            enlargeCenterPage: true,
            enableInfiniteScroll: true,
            autoPlayAnimationDuration: Duration(seconds: 1),
            autoPlayCurve: Curves.linear,
            height: MediaQuery.of(context).size.height * 0.35,
            autoPlay: true,
            reverse: false,
            autoPlayInterval: Duration(seconds: 3),
            pauseAutoPlayOnTouch: Duration(seconds: 10),
            // autoPlayInterval: Duration(seconds: 1),
            items: [
              'assets/news0.png',
              'assets/news1.png',
              'assets/news2.png',
            ].map((i) {
              return Builder(
                builder: (BuildContext context) {
                  return Container(
                    width: MediaQuery.of(context).size.width,
                    margin: EdgeInsets.symmetric(horizontal: 5.0),
                    decoration: BoxDecoration(color: Colors.white),
                    child: GestureDetector(
                      child: Image.asset(i, fit: BoxFit.fill),
                      onTap: () {
                        Navigator.pushReplacement(
                          context,
                          MaterialPageRoute(
                              builder: (BuildContext context) => NewsPage()),
                        );
                      },
                    ),
                  );
                },
              );
            }).toList(),
          ),
          Expanded(),
dart flutter
1个回答
0
投票

CarouselSlider已经自动在这里是我的代码,对我来说工作得很好,你添加一个孩子的(项目)

 static List<String> imgList;
  int _current = 0;

static List<T> map<T>(List list, Function handler) {
    List<T> result = [];
    for (var i = 0; i < list.length; i++) {
      result.add(handler(i, list[i]));
    }

    return result;
  }    

         static List child = imgList.length > 0 ?  map<Widget>(
            imgList,
            (index, i) {
              return Container(
                margin: EdgeInsets.all(5.0),
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(5.0)),
                  child: Stack(children: <Widget>[
                    Image.network(i, fit: BoxFit.cover, width: 1000.0),
                    Positioned(
                      bottom: 0.0,
                      left: 0.0,
                      right: 0.0,
                      child: Container(
                        decoration: BoxDecoration(
                          gradient: LinearGradient(
                            colors: [
                              Color.fromARGB(200, 0, 0, 0),
                              Color.fromARGB(0, 0, 0, 0)
                            ],
                            begin: Alignment.bottomCenter,
                            end: Alignment.topCenter,
                          ),
                        ),
                        padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
                        child: Text(
                          'No. $index image',
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 20.0,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  ]),
                ),
              );
            },
          ).toList():null;

        //then you build your slider

             CarouselSlider(
                items: child,
                autoPlay: true,
                enlargeCenterPage: true,
                aspectRatio: 2.0,
                onPageChanged: (index) {
                  setState(() {
                    _current = index;
                  });
                },
              ),
© www.soinside.com 2019 - 2024. All rights reserved.