I am having trouble updating a list in my flutter app. Basically I want to load a list from a textfile when I load a page, that part works fine. However, when I try to place that list into my global variables, nothing happens. It seems like a really simple problem but I haven't stumbled across something like this in other programming languages like Java and Python.
Here is a simple recreation of the problem
List<String> firstList = [1,2,3,4,5];
globals.secondList = firstList;
If I would now write simple print-debugs as follows:
print(globals.secondList);
print(firstList);
I would get the output: [] [1,2,3,4,5]
It worked earlier when I had all my lists inside the StateFulWidget and used setState() in my setup function. Am I just missing something really basic here, or what is the problem? Thankful for any advice!
Edit: I'm just gonna link the original code
Here are the setups inside my StateFulWidget (inside the class _...State extends State<...>)
@override
void initState() {
super.initState();
startTimer();
_setup();
print(globals.selectedList);
}
void filterList(List<String> selectedList){
selectedList.removeWhere((element) => usedCelebs.contains(element));
}
Future<List<String>> _loadQuestions(filePath) async {
List<String> celebs = [];
await rootBundle.loadString(filePath).then((names) {
for (String i in LineSplitter().convert(names)) {
celebs.add(i);
}
});
return celebs;
}
_setup() async {
// Retrieve the questions (Processed in the background)
List<String> names_350 = await _loadQuestions('assets/350_people.txt');
names_350.removeWhere((element) => usedCelebs.contains(element));
List<String> names_4000 = await _loadQuestions('assets/4000_people.txt');
globals.people_350 = names_350;
globals.people_4000 = names_4000;
// Notify the UI and display the questions
}
and here is my global library
library globals;
List<String> people_350 = [];
List<String> people_4000 = [];
bool allowPass = false;
bool allowThieves = false;
int originalTime = 45;
int nbrTeams = 2;
int maxPoints = 16;
List<String> selectedList = people_350;