flutter轮播

 

pubspec.yaml

dependencies:
  carousel_slider: ^4.0.0

main.dart

//Import the package in your Dart file:
import 'package:carousel_slider/carousel_slider.dart';

final List<Widget> imageList = [
  Image.network('https://example.com/image1.jpg'),
  Image.network('https://example.com/image2.jpg'),
  Image.network('https://example.com/image3.jpg'),
];

CarouselSlider(
  items: imageList,
  options: CarouselOptions(
    height: 400,
    aspectRatio: 16/9,
    viewportFraction: 0.8,
    initialPage: 0,
    enableInfiniteScroll: true,
    reverse: false,
    autoPlay: true,
    autoPlayInterval: Duration(seconds: 3),
    autoPlayAnimationDuration: Duration(milliseconds: 800),
    autoPlayCurve: Curves.fastOutSlowIn,
    enlargeCenterPage: true,
    onPageChanged: (index, reason) {
      // Do something when the page changes
    },
    scrollDirection: Axis.horizontal,
  ),
);

  

posted @ 2023-03-20 17:47  小小强学习网  阅读(84)  评论(0)    收藏  举报