gpt4 book ai didi

listview - 插入新记录后如何重新加载列表?

转载 作者:行者123 更新时间:2023-12-03 03:09:35 24 4
gpt4 key购买 nike

我有一个listView,它是使用Future Builder创建的,所有数据都是从服务器获取的,添加新记录后,一条记录已成功添加到数据库中,并且Navigate.pop已成功添加到listView页面,但是我的列表未刷新,我该如何刷新我的列表 list ?

FutureBuilder<List<NewAddressModel>>(
future: myAddressList,
builder: (context, snapshot) {
print(snapshot);
if (snapshot.hasData)
return addressList(snapshot.data);
else if (snapshot.hasError)
return _buildErrorPage(snapshot.error);
else
return _buildLoadingPage();
},
),
Widget _buildErrorPage(error) => Material(
child: Center(
child: Text("ERROR: $error"),
),
);
Widget _buildLoadingPage() => Material(
child: Center(
child: CircularProgressIndicator(),
),
);

IconButton (
icon: Icon(Icons.add_location),
onPressed: navigateToAddAddress
)

void navigateToAddAddress() async {
await Navigator.push(context, MaterialPageRoute(builder: (context) {
return AddAddress();
}));
}

最佳答案

像这样使用Navigator.push()。whenComplete((){setState(){}}),如@Abjox建议的那样。

void navigateToAddAddress() async {
Navigator.of(context).push
(new MaterialPageRoute(builder: (context) => AddAddress()))
.whenComplete((){setState(() {
// use here that method by which you load data into listView
});});
}

关于listview - 插入新记录后如何重新加载列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60056850/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com