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,
),
);

浙公网安备 33010602011771号