[英]How do I create Flutter stream builder?
I have an "updateDatabase" function that retrieves the data from the Firebase Real-Time Database and saves it in the shared preferences... I put this function in the Init State of my home page but I would like this to become a stream builder so as not to having to reopen the page each time to get updated data but have them immediately. I have an "updateDatabase" function that retrieves the data from the Firebase Real-Time Database and saves it in the shared preferences... I put this function in the Init State of my home page but I would like this to become a stream builder这样就不必每次都重新打开页面来获取更新的数据,而是立即拥有它们。
This is part of my updateDatabase function:这是我的更新数据库 function 的一部分:
updateDatabase() async {
final prefs = await SharedPreferences.getInstance();
DatabaseReference starCountRef =
FirebaseDatabase.instance.ref('/utenti/$uid/');
starCountRef.onValue.listen((DatabaseEvent event) {
final data = event.snapshot.value as Map;
prefs.setInt("videoAgosto2022", data["videoAgosto2022"]);
ect...
}
This is part of my home page...这是我主页的一部分...
Widget build(BuildContext context) { double altezza = MediaQuery.of(context).size.height;小部件构建(BuildContext context){ double altezza = MediaQuery.of(context).size.height;
return StreamBuilder(
stream: What should I put here?,
builder: (context, snapshot) => SingleChildScrollView(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Column(
What should I put in the "dada" field?我应该在“dada”字段中输入什么?
A stream function must be marked as async*
A stream function 必须标记为async*
Then, you just have to put your function in the stream
attribute of the StreamBuilder
widget然后,您只需将 function 放入StreamBuilder
小部件的stream
属性中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.