我用https://pub.dev/packages/inview_notifier_list这个库来实现。在低层设备中,它可能会导致性能问题。像jank,框架问题。
这里是例子。希望对您有所帮助。
SafeArea(
child: Stack(
children: [
InViewNotifierCustomScrollView(
physics: Platform.isAndroid ? ClampingScrollPhysics() : RangeMaintainingScrollPhysics(),
isInViewPortCondition: widget.inViewPortCondition ??
(double deltaTop, double deltaBottom, double vpHeight) {
return deltaTop < (0.7 * vpHeight) && deltaBottom > (0.7 * vpHeight);
},
endNotificationOffset: mw(500),
onListEndReached: () async{
if(_list1.length == _totCnt) {
setState(() {
_noMoreItem = 'No more Models';
});
} else {
if(_moreItems) {
setState(() {
_isLoad = true;
_moreItems = false;
_offset = _offset + 30;
});
bool _rrr = await getModelList($user.accessToken, $user.appInfo);
if(_rrr) {
setState(() {
_moreItems = true;
});
}
} else {
}
}
},
controller: _bscrollController,
slivers: [
SliverAppBar(
automaticallyImplyLeading: false,
elevation: 0,
brightness: Brightness.light,
title: Text('Models', style: Ts.h15bb(),),
actions: [
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
Navigator.push(context,MaterialPageRoute(builder: (context) => SearchPage()));
},
child: Icon(Icons.search, size: mw(26),)),
SizedBox(width: mw(10),),
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
Navigator.push(context,MaterialPageRoute(builder: (context) => CartPage()));
},
child: Stack(
children: [
Padding(
padding: EdgeInsets.only(top: mw(13), right: mw(18)),
child: Image.asset('assets/pickling_cart.png', width: mw(18), height: mw(22),),
),
$user.cartCnt == '0' ? Container():Positioned(
top: mw(9),
right: mw(10),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
height: mw(16),
padding: EdgeInsets.only(left: mw(5), right: mw(5), bottom: mw(2)),
color: Colors.black,
child: Center(child: Text('${$user.cartCnt}', style: Ts.ctwb(),),),
),
)
)
],
)),
],
),
_totCnt == 0 ?
SliverToBoxAdapter(
child: Padding(
padding: EdgeInsets.only(top:mw(50)),
child:
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('There are no models!', style: Ts.h3bb()),
SizedBox(height:mw(5)),
Text(':X', style: Ts.bd1gm(),),
],
))
),
):
SliverPadding(
padding: EdgeInsets.only(top: mw(2)),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Column(
children: [
ModelItem(imgURL,index,$user),
Divider(thickness: 1, color: Du.lightGrey(),)
],
);
},
childCount: _list1.length
)
)
)
],
),
],
)
);