-
-
Save aduquet/f04b5f780f9d34c6e031ce0b74af5ab7 to your computer and use it in GitHub Desktop.
Async data on InitState method - dart/flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I was struggling in finding a way to load async data on Initial State method | |
I found the answer here: https://stackoverflow.com/questions/51901002/is-there-a-way-to-load-async-data-on-initstate-method | |
This is my concrete example | |
setInitialValueQuestionReview() async { | |
late DocumentReference<Map<String, dynamic>> testAnwDB = FirebaseFirestore | |
.instance | |
.collection('AppUsers') | |
.doc(currentUser!.uid) | |
.collection('test_settings') | |
.doc('personalised_Settings'); | |
var querySnapshot = await testAnwDB.get(); | |
var personalisedSettingsData = querySnapshot.data(); | |
_questionReview.text = personalisedSettingsData!['reviewSesion'].toString(); | |
_isSelectedShowBoth = personalisedSettingsData['showBoth']; | |
_isSelectedShowCorrectas = personalisedSettingsData['showCorr']; | |
_isSelectedShowIncorrectas = personalisedSettingsData['showInCorr']; | |
} | |
@override | |
void initState() { | |
super.initState(); | |
WidgetsBinding.instance?.addPostFrameCallback((_) { | |
setInitialValueQuestionReview(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment