你好,我正在尝试在我的列表中使用分页。并且列表数据来自firebase。我不确定如何使用流构建器对数据进行分页。现在我通过在 didChangeDependencies() 函数中调用 getdocuments 来进行分页。但在添加新数据后,列表不会更新。如果有人可以提供帮助,那么这对我来说会很棒。这是我现在在做什么..
didChangeDependencies() {
super.didChangeDependencies();
getProducts();
_scrollController.addListener(() {
double maxScroll = _scrollController.position.maxScrollExtent;
double currentScroll = _scrollController.position.pixels;
double delta = MediaQuery.of(context).size.height * 0.20;
if (maxScroll - currentScroll <= delta) {
getProducts();
}
});
}
getProducts() async {
if (!hasMore) {
return;
}
if (isLoading) {
return;
}
setState(() {
isLoading = true;
});
QuerySnapshot querySnapshot;
if (lastDocument == null) {
querySnapshot = await firestore
.collection('products')
.limit(documentLimit)
.orderBy('timestamp', descending: true)
.getDocuments();
} else {
querySnapshot = await firestore
.collection('products') …
Run Code Online (Sandbox Code Playgroud) pagination firebase flutter google-cloud-firestore stream-builder
我正在创建一个项目,我需要在 appbar 中显示一个进度条。代码如下
bool loader_saver=false;
return Scaffold(
appBar: new AppBar(
title: new Text("add data"),
actions: <Widget>[
loader_saver?
new CircularProgressIndicator()
:
new FlatButton(
onPressed: () {
_add_Data();
},
child: new Icon(
Icons.save,
color: Colors.white,
))
],
)
Run Code Online (Sandbox Code Playgroud)
这是 onpressed 方法
void _add_data(){
final _formstate = _form_key.currentState;
if (_formstate.validate()) {
_form_key.currentState.save();
setState(() {
loader_saver=true;
});
}
}
Run Code Online (Sandbox Code Playgroud)