Flutter:StreamBuilder使用旧流而不是新流

时间:2018-06-29 17:28:59

标签: database dart google-cloud-firestore real-time flutter

我正尝试使用Flutter的StreamBuilder在Flutter应用上显示Google Firestore实时列表。

但是,流似乎同时使用了旧数据和新数据,而不仅仅是新数据。 (见下文)

SELECT qcat.name,
COUNT( CASE WHEN qas.state = "todo" THEN 1 END ) AS gtotal,
COUNT( CASE WHEN qas.state = "gradedright" THEN 1 END ) AS rightanswer, 
COUNT( CASE WHEN qas.state = "gradedwrong" THEN 1 END ) AS wronganswer, 
SUM(qas.fraction) AS grade,
quiza.id 
FROM mdl_quiz_attempts quiza
JOIN mdl_question_attempts qa ON qa.questionusageid = quiza.uniqueid 
JOIN mdl_question_attempt_steps qas ON qas.questionattemptid = qa.id 
JOIN mdl_question qstn ON ( qa.`questionid` = qstn.id ) 
JOIN mdl_question_categories qcat ON ( qstn.`category` = qcat.id ) 
WHERE quiza.id=1173 and FIND_IN_SET(qstn.id, (1,2,3,4,5,6)) GROUP BY quiza.id,qcat.name

1st I pick CS115 and the date which gets me the correct list (click for picture)

The document IDs are also correct (output of debugPrint):

但是,一旦我change the class to CS331this happens

如您所见,CS331的前三个文档ID与CS115的ID完全相同。似乎流在使用新数据之前只是使用以前存在的任何数据。我不明白为什么会这样,因为每次dropDownItem更改时我都会调用setState,以便可以重新构建整个窗口小部件(从而使用更新的数据重新生成新的流对象)。这将导致新UI使用旧数据的值。我已经在这个问题上停留了几天,似乎没有任何效果。有谁知道如何解决这个奇怪的错误?预先感谢!

0 个答案:

没有答案