简体   繁体   中英

CarouselSlider start point flutter

Here is my code.

@override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.red,
      padding: EdgeInsets.all(7),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text('지금 뜨는 콘서트'),
          Material(
            color: Colors.lightGreen,
            child: CarouselSlider(
              items: makeBoxImages(context, concerts),
              options: CarouselOptions(
                viewportFraction: 0.3,
                enableInfiniteScroll: false,
                initialPage: 1,
              ),
            ),
          ),
        ],
      ),
    );
  }
List<Widget> makeBoxImages(BuildContext context, List<Concert> concerts) {
  List<Widget> results = [];
  for (var i = 0; i < concerts.length; i++) {
    results.add(
      Material(
        color: Colors.yellow,
        child: Column(
          children: [
            Container(
              color: Colors.blue,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Image.asset(
                    'assets/images/' + concerts[i].poster,
                    width: MediaQuery.of(context).size.width * 0.25,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Icon(
                        kIconMap[concerts[i].kinds],
                        size: 15,
                      ),
                      Text(concerts[i].kinds),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
  return results;
}

and then, screen showed like this.

在此处输入图像描述

when i scroll left to right screen showed like this.

在此处输入图像描述

After that the screen fixed.


At this point, I have a two question.

  1. I want to make the first screen like this. Is it possible? 在此处输入图像描述

  2. When slider's first element in a screen is leftmost, I want to fix it (when user scroll left to right)

like the 1st image not 2nd image.

Thank you for reading my question.

If I get your issue clearly, then the solution is to switch the padEnds to false

 options: CarouselOptions(
 padEnds : false)

Hopefully this will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM