Firebase呼叫数据



我的第一个代码:

Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 0,
),
child: Text(
" i want get data here",
style: TextStyle(
color: Color(0xFF737599),
),
),
),

这是我的第二个代码:

return Container(
color: Colors.white,
child: Container(
height: size.height * 0.4,
child: StreamBuilder<QuerySnapshot>(
stream: _statusService.getStatus(),
builder: (context, AsyncSnapshot snapshot) {
return !snapshot.hasData
? CircularProgressIndicator()
: ListView.builder(
itemCount: 1,
itemBuilder: (context, index) {
DocumentSnapshot movies = snapshot.data.docs[2];
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 0,
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 0,
),
child: Text(
"${movies['description']}",
style: TextStyle(
fontSize: 10,
color: Color(0xFF737599),
),
),
),
);
});
}),
),
);

我想从firebase拉一个文本。我设法做到了这一点(在不同的dart页面上),但是我如何将其集成到我之前编写的代码中(有一部分我在没有使用firebase的情况下手动打印文本,我如何将其集成到该部分中)。

简而言之,我想在第一个代码中集成文本部分,在第二个代码中我从法老那里获得数据的部分。

我正在分享这两部分代码,你能帮忙吗?

这不是最好的做法但是你可以创建class属性并在第二段代码中赋值,比如

var yourVar = "";

Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 0,
),
child: (yourVar!="")?Text(
yourVar,
style: TextStyle(
color: Color(0xFF737599),
),
) ?null,
),
```
in your second code 
```
return Container(
color: Colors.white,
child: Container(
height: size.height * 0.4,
child: StreamBuilder<QuerySnapshot>(
stream: _statusService.getStatus(),
builder: (context, AsyncSnapshot snapshot) {
return !snapshot.hasData
? CircularProgressIndicator()
: ListView.builder(
itemCount: 1,
itemBuilder: (context, index) {
DocumentSnapshot movies = snapshot.data.docs[2];
setState(() { yourVar= newValue; });
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 0,
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 0,
),
child: Text(
"${movies['description']}",
style: TextStyle(
fontSize: 10,
color: Color(0xFF737599),
),
),
),
);
});
}),
),
);

最新更新