Flutter 在颤振中如何触发转盘滑块端部的功能?
我已经使用该软件包在我的应用程序中向我的用户显示帖子。 每当用户到达传送带中的最后一个帖子时,我想加载更多帖子。 在哪里可以触发将向项目列表添加更多数据的函数,在这种情况下 家庭数据 这就是我的代码的外观:Flutter 在颤振中如何触发转盘滑块端部的功能?,flutter,dart,carousel,dart-pub,Flutter,Dart,Carousel,Dart Pub,我已经使用该软件包在我的应用程序中向我的用户显示帖子。 每当用户到达传送带中的最后一个帖子时,我想加载更多帖子。 在哪里可以触发将向项目列表添加更多数据的函数,在这种情况下 家庭数据 这就是我的代码的外观: @override Widget build(BuildContext context) { return RefreshIndicator( onRefresh: getMoreData, //fetches new post on refresh child: Car
@override
Widget build(BuildContext context) {
return RefreshIndicator(
onRefresh: getMoreData, //fetches new post on refresh
child: CarouselSlider(
options: CarouselOptions(
height: 650,
enableInfiniteScroll: false,
aspectRatio: 2.0,
enlargeCenterPage: true,
scrollDirection: Axis.vertical,
),
items: homeData, //list of widgets that are displayed in the carousel
),
);
}
您可以对
onPageChanged
进行回调,每次刷帖时都会调用该回调。
以下是您如何做到这一点:
List itemList = [1,2,3,4,5];
CarouselSlider(
options: CarouselOptions(
height: 400.0,
onPageChanged: (index, reason) {
if(index == itemList.length - 1) {
//do whatever you want to do on your last page change
}
},
),
items: itemList.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.amber
),
child: Text('text $i', style: TextStyle(fontSize: 16.0),)
);
},
);
}).toList(),
)