firebase - 文本小部件将实时 Fireabase 值检测为空
问题描述
我想从我的实时数据库中获取这些值并将它们放入我的Text
小部件中我已经在我的应用程序中成功检索到它们唯一的问题是使它们在我的Text
小部件中可用
这些是我想String
从实时数据库中获取的文本小部件
第一个文本小部件
Text(
getSnapShotData('orders_count'),//here is the function being run
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: "Sofia_Pro",
fontWeight: FontWeight.w300,
),
),
第二个文本小部件
Text(
getSnapShotData('name'),//here is the function being run
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: "Sofia_Pro",
fontWeight: FontWeight.w300,
),
),
从实时数据库中获取的功能
String getSnapShotData(String child){
databaseReference.child("users").child(_firebaseUser.uid).child(child).once().then((DataSnapshot snapshot) {
var foo = snapshot.value;
var fooString = snapshot.value.toString();
print(snapshot.value);
print("type is ${foo.runtimeType}");
print("type is ${fooString.runtimeType}");
return fooString;
});
}
有趣的是,如果我记录获取的值,我会得到正常的结果,唯一的问题是当我将获取的数据用于Text
小部件时
这是获取数据的日志结果
I/flutter (29458): 4
I/flutter (29458): type is int
I/flutter (29458): type is String
解决方案
推荐阅读
- python - Fortran 代码仅在通过 python 运行时才会出错
- android-studio - 避免背景颜色混合android studio
- hazelcast - 无论如何要获得 Hazelcast 列表的大小?
- node.js - 当我的对象即将被 Node 中的 GC 收集时,我可以得到回调吗?
- sfinae - 使用 SFINAE 在 C++98 中检测联合成员的可用性
- r - 更改 geom_smooth 中的线条边框颜色
- vue.js - 仅显示带有 category_name 的 API 数据:Vue 中的“WEBSITE”
- vba - 访问拆分表单上的多个过滤器中的不同或唯一计数
- image - 尽管使用 WebP 格式的图像,“为下一代提供图像”问题仍然存在
- git - 推送到本地网络 git repos 错误代码 403 致命:HTTP 请求失败