Skip to content

Instantly share code, notes, and snippets.

@md-weber
Last active July 11, 2020 17:39
Show Gist options
  • Save md-weber/5e1cdba4e5c431042a94d37e114aec1e to your computer and use it in GitHub Desktop.
Save md-weber/5e1cdba4e5c431042a94d37e114aec1e to your computer and use it in GitHub Desktop.
Future getPosts(BuildContext context) async {
int index = getFromSF();
QuerySnapshot querySnapshot =
await Firestore.instance.collection('fortunepool').getDocuments();
if (indexList.contains(index)) {
// TODO: get any other document
int currentIndex = index;
String myFortune = "";
// This should return you the next title
while(index < querySnapshot.documentChanges.length && indexList.contains(currentIndex)){
myFortune = querySnapshot.documents[index++].data['title'];
currentIndex = index++;
}
myFortune = querySnapshot.documents[index++].data['title'];
currentIndex = index++;
}
saveDocumentInSharedPreferences(myFortune);
setIndexToSharedFortune(index);
indexList.add(index);
saveIndexNumbers(indexList, "listofIndexes");
} else if (indexList.isEmpty || index == 5) {
// Keep this part if is working
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment