为什么我的窗口小部件仅加载而不返回数据? [英] Why my widget is only loading and not returning data?
本文介绍了为什么我的窗口小部件仅加载而不返回数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图弄清楚为什么我的小部件只加载而不给数据提供代码
Im trying to figuring our why my widget is only loading and not giving data heres the code
Stream myVideos;
int videos = 0;
getalldata() async {
String myID = FirebaseAuth.instance.currentUser.uid;
//get videos as future
myVideos = FirebaseFirestore.instance.collection('videos').snapshots();
var documents = FirebaseFirestore.instance.collection('videos').snapshots();
videos = await documents.length;
await for (var snapshot in documents) {
for (var doc in snapshot.docs) {
likes = doc.data()['likes'].length + likes;
}
}
var followersdocuments = FirebaseFirestore.instance
.collection("meinprofilsettings")
.doc(myID)
.collection('followers')
.snapshots();
var followingdocuments = FirebaseFirestore.instance
.collection("meinprofilsettings")
.doc(myID)
.collection('following')
.snapshots();
followers = await followersdocuments.length;
following = await followingdocuments.length;
setState(() {
dataisthere = true;
});
}
Widget getBody(BuildContext context) {
return dataisthere == false
? Scaffold(body: Center(child: CircularProgressIndicator()))
: Stack(children: <Widget>[
Scaffold(
key: _scaffoldKey,
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0.0,
title: Text("Search App"),
actions: [
IconButton(
icon: Icon(Icons.search),
onPressed: () {
Navigator.of(context)
.pushNamed(Searchuserinhomepage.route);
},
),
IconButton(
icon: Icon(Icons.camera_alt_sharp),
onPressed: () {
showPickOptionsDialog(context);
// _showPickOptionsDialog(context);
},
),
],
),
drawer: Seitenleiste(),
body: RefreshIndicator(
onRefresh: _handleRefresh,
color: Colors.black,
strokeWidth: 4,
child: ListView(children: [
Column(
children: <Widget>[
Allcategories(),
SizedBox(
height: 5,
),
StreamBuilder(
stream: myVideos,
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
}
if (videos >0) {
Ans发生的事情是它唯一的加载如果您需要更多信息,请发表评论.如果您还需要更多代码,请留下评论.我想要的是将视频流式传输.在我认为它们是未来之前,但不是那时,应该成为潮流,但是我错了什么?
Ans what happen is its only loading If you need more information please leave a comment . If you need more code also please leave comment . What I want is getting the videos as a stream . before they was a future but not then should be a stream I think but what do I wrong ?
推荐答案
您的代码正在获取 .snapshots()
,但实际上并没有通过调用数据提取.listen()
调用.
Your code is getting the .snapshots()
but it is not then actually invoking the fetching of the data via the .listen()
call.
请在收听实时更改中查看整个部分.
这篇关于为什么我的窗口小部件仅加载而不返回数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文