I'm trying to load different values from a .txt file line by line.
I'm loading an file from assets, which is already registered in pubspec.yaml.
Future<String> getFileData() async {
return await rootBundle.loadString('assets/files/text.txt');
}
As this returns one long String I split it into a list:
void doStuff() async {
await getFileData().then((value) => value.split('\n').forEach((element) {
exampleQuestions.add(element);
}));
}
This method is called in my class - constructor which is called from my Main by a named route:
GameOver.routeName: (context) => GameOver(),
'/game': (context) => Game(
),
},
exampleQuestion get's filled in the doStuff() - method (already checked that), but looses it's values in the _GameState class where the widget, that want's to access the list returns an out of index exception.
However if i quick reload my application the values are set correctly. If I then click the button to continue again nothing changes until I quick reload.
Any hints are very appreciated ..
setStatemethod when you add elements to the list