firebase - 使用 TabBarView 和 DefaultTabController 时的 initState()
问题描述
我在 initState 方法中从 firestore 加载数据。如果屏幕不是 a 的一部分,TabBarView()
它会按预期工作,而TabBarView
我必须热重新加载才能加载数据。
//我是如何创建 mt 选项卡的
return DefaultTabController(
length: 4,
child: Scaffold(
appBar: AppBar(centerTitle: true,
title: Text("tabs", style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white)),
bottom: TabBar(
indicatorColor: Colors.white,
tabs: <Widget>[
Tab(
icon: Image.asset(
"assets/icons/tools.png",
height: 40,
),
child: Text("tab0",style: TextStyle(fontSize: 10),),
),
Tab(
icon: Image.asset(
"assets/icons/il.png",
height: 40,
),
child: Text("tab1",style: TextStyle(fontSize: 10)),
),
Tab(
icon: Icon(Icons.lock),
child: Text("tab2"),
),
Tab(
icon: Icon(Icons.lock),
child: Text("tab3"),
),
],
),
),
body: TabBarView(children: <Widget>[
Tab0(),
Tab2(),
Tab2(),
Tab3()
],),
),
);
以下是我在 Tab3 中从 cloudfirestore 加载数据的方式:
getIssues() async {
final FirebaseUser fbUser = await FirebaseAuth.instance.currentUser();
final String user = fbUser.uid;
return await Firestore.instance
.collection('users')
.document(user)
.collection('mydata')
.getDocuments();
}
我的initState
:
QuerySnapshot querySnapshot;
@override
void initState() {
super.initState();
getIssues().then((results) {
querySnapshot = results;
});
}
解决方案
也许你试试这个:
@override
void initState() {
super.initState();
getIssues().then((results) {
setState(() {
querySnapshot = results;
});
});
}
推荐阅读
- r - 使用特定分配的数字循环
- powershell - 每月清理日志的 Powershell 脚本
- amazon-web-services - Terraform、ElasticSearch、模块、cloudposse/terraform-aws-elasticsearch
- pyaudio - Pa_GetDeviceInfo() 和 PaAsio_GetAvailableBufferSizes() 的行为
- kotlin - 使用 micronaut、Gradle 和 Kotlin 找不到页面消息
- json - 杰克逊 JsonInclude Non_Null 不忽略嵌套对象属性的工作
- node.js - 我的 mongodb 数据库在它工作之前有问题,但我不知道为什么现在不能工作
- c++ - 在 Visual Studio 2019 中使用 C++ 中的 MySQL
- python - for 循环中的 objects.location 请求不会更新
- javascript - 类型错误:不是 NODE JS DIScord Bot 中的函数