Firebase 如何减少Flatter中firestore读取的数量
我正在构建一个应用程序,使用streambuilder从firestore获取数据 我在firestore上只写了6个文档,但一部手机就可以读取350多个文档,请问我如何减少阅读量 我还看了一篇关于如何使用缓存来减少读取次数的文章,但这是针对Java(Android)的,我不知道如何在Flatter中使用它Firebase 如何减少Flatter中firestore读取的数量,firebase,flutter,dart,caching,google-cloud-firestore,Firebase,Flutter,Dart,Caching,Google Cloud Firestore,我正在构建一个应用程序,使用streambuilder从firestore获取数据 我在firestore上只写了6个文档,但一部手机就可以读取350多个文档,请问我如何减少阅读量 我还看了一篇关于如何使用缓存来减少读取次数的文章,但这是针对Java(Android)的,我不知道如何在Flatter中使用它 StreamBuilder<QuerySnapshot>( stream: Firestore.instance
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection("free")
.where("created", isGreaterThan: DateTime.now().subtract(Duration(hours: 24)))
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text('.....Loading');
}
return ListView.builder(
scrollDirection: Axis.vertical,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
DocumentSnapshot free =
snapshot.data.documents[index];
return Container(
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
Text(
'${free['safe']['time']}',
style: TextStyle(fontSize: 18),
),
SizedBox(
height: 3,
),
Text(
'${free['safe']['date']}',
style: TextStyle(fontSize: 13),
),
],
),
//尺寸箱(宽度:20,)
你需要将你用来读取Firebase数据的代码添加到你的问题中,以便任何人能够提供帮助我刚刚添加了代码这可能更像是一种编程方法来解决问题,而不是与颤振相关的方法。我建议的一件事是尝试在函数的消息中缓存不同的值,而不是ID,并且永远不要在构建函数中执行数据库操作,因为这会增加读取。我在构建函数之外执行数据库操作,但我的读取仍在增加这将由联系Firebase支持团队,因为他们可以更仔细地了解读取量增加的原因。您需要将用于读取Firebase数据的代码添加到您的问题中,以便任何人能够提供帮助。我刚刚添加了代码。这可能更像是一种编程方法来解决问题,而不是与颤振相关的方法。我建议的一件事是尝试在函数的消息中缓存不同的值,而不是ID,并且永远不要在构建函数中执行数据库操作,因为这会增加读取。我在构建函数之外执行数据库操作,但我的读取仍在增加这将由联系Firebase支持团队,因为他们可以更仔细地了解读数增加的原因。
SizedBox(
width:
0.5 * MediaQuery.of(context).size.width,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'${free['safe']['league']}',
style: TextStyle(fontSize: 15),
),
SizedBox(
height: 2,
),
Text(
'${free['safe']['home']}',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500),
),
SizedBox(
height: 3,
),
Text(
'vs ${free['safe']['away']}',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500),
),
SizedBox(
height: 3,
),
Text(
'${free['safe']['tip']}',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.redAccent),
),
],
),
),
Column(
children: [
Text(
'${free['safe']['odd']}',
style: TextStyle(fontSize: 18),
),
SizedBox(
height: 4,
),
Builder(
builder: (context) {
if (free['safe']['result'] == 'win') {
return Column(
children: [
Icon(
Icons.check_circle,
color: Colors.green,
),
SizedBox(
height: 8,
),
Text(
'WON',
style: TextStyle(
color: Colors.green,
fontWeight:
FontWeight.bold),
)
],
);
} else if (free['safe']['result'] ==
'loss') {
return Column(
children: [
Icon(
Icons.close,
color: Colors.red,
),
SizedBox(
height: 8,
),
Text(
'LOSS',
style: TextStyle(
color: Colors.red,
fontWeight:
FontWeight.bold),
)
],
);
} else {
return Text('...');
}
},
),
],
),
],
),
);
});
}),