【发布时间】:2020-01-16 09:53:49
【问题描述】:
我正在尝试获取属于已登录用户的数据,但是,由于某种原因,“getuserui”是异步的。即使用户已登录在应用程序内执行操作,该函数仍会返回 Future....
我已经数不清自己尝试了多少不同的东西,包括 .then 等,但这是我最近的尝试。
@override
Widget build(BuildContext context) {
return SizedBox(
height: 900,
child: StreamBuilder(
stream: () async{
fireFirestore.instance.collection('properties').where('uid', isEqualTo: await _authService.getUserId()) .snapshots(),
},
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (!snapshot.hasData)
return const Text('Loading...');
else {
return ListView.builder( ...............
如果您需要查看 getUserId():
Future<String> getUserId() {
return _auth.currentUser().then((value) => value.uid.toString());
}
(我已经在将来的方式(.then)和异步方式(async await)中完成了这个方法
它只是告诉我the argument type Future<null> can't be assigned to the parameter type Stream
【问题讨论】: