我使用下面的代码来检索颤振应用程序中的列表,使用分页和 firestore 作为数据库,工作正常。我指的是flutter_native_admob
原生广告的依赖性。但我不知道如何在listview.builder
同时我需要实现分页。
就像在 Instagram 中一样,在发布一定数量的帖子后,原生广告就会出现,我需要以类似的方式显示添加内容。这怎么可能?
_getProducts() async {
query = Firestore.instance.collection("users").document(uid).collection('my_favorites').orderBy("timestamp", descending: true).limit(5);
setState(() {
_loadingnotifications = true ;
});
QuerySnapshot _querySnapshot = await query.getDocuments();
_lastDocument = _querySnapshot.documents[_querySnapshot.documents.length - 1];
_notifications = _querySnapshot.documents;
setState(() {
_loadingnotifications = false;
});
}
_getMoreNotifications() async {
print("new docs loaded");
if(_moreProductsAvailable == false ){
return;
}
if(_loadingMore == true ){
return;
}
_loadingMore = true;
query = Firestore.instance.collection("users").document(uid).collection('my_favorites').orderBy("timestamp", descending: true).startAfter([_lastDocument.data['timestamp']]).limit(5);
QuerySnapshot _querySnapshot = await query.getDocuments();
if (_querySnapshot.documents.length <5){
_moreProductsAvailable = false;
}
_lastDocument = _querySnapshot.documents[_querySnapshot.documents.length - 1];
_notifications.addAll(_querySnapshot.documents);
setState(() {
_loadingnotifications = false;
});
_loadingMore = false;
}
列表视图生成器
Flexible(
child:_loadingnotifications == true ? Container(child: Center(child: Text("Loading..."),),) :Container(child: _notifications.length == 0? Center(
child: Text("No Marked Posts Yet!"),) :
new ListView.builder(
controller: _scrollController,
itemCount: _notifications.length,
itemBuilder: (BuildContext ctx, int index){
String itemTitle = _notifications[index].data['itemTitle'];
return ItemCard(itemTitle: itemTitle, );
}),)
),
我知道如何创建 admob 帐户并初始化flutter_native_admob
在应用程序中,但不知道如何将其放入列表中,就像 Instagram 和分页一样。