I have a function named splitVendorMainCategory, which simply splits a List into two subLists, described as:
List vendorMainCategory = ['one', 'two', 'three', 'four'];
Future splitVendorMainCategory() async {
for (int i=0; i< (vendorMainCategoryLength); i+=2){
vendorMainCategoryC1.add(vendorMainCategory[i]),
},
for(int j = 1; j < vendorMainCategoryLength; j+=2){
vendorMainCategoryC2.add(vendorMainCategory[j]),
}
}
And I call it right at the initialisation of the page, but it returns two empty sub-lists, while the List VendorMainCategory contains elements. I call the function as:
@override
initState() {
splitVendorMainCategory();
super.initState();
}
However, when I call the same function in 'body' of the same page, it returns the expected result.
vendorMainCategoryC1 = [one, three]
vendorMainCategoryC2 = [two, four]
What could be causing the function to not be called at the initialisation of the page, but make it work completely fine when called inside another widget? No error is thrown when I try to run it either way, just that I get two different results. Any help will be highly appreciated.