Send parameter to class, but the class is wraped with array

Viewed 23

So i have some class that is wrap with array caled screenData, and i want to pass indexTheme to each of these class.

  
  int indexTheme = 1;

  final screenData = [
    const homeTest(),
    const productPage(),
    const trading(),
    const inventoryPage(),
    const masterPage(),
    const financePage(),
  ];

i can simply just pass data like this, but in the future i want to change value of int.

    int indexTheme = 1;

    const homeTest(
       indexTheme = 1;
    ),
1 Answers

You can use for loop to pass parameters

Void changeIndexTheme(int newIndexTheme){
    for(var classInstance in screenData){ //instead of var it's better to write your class name
        classInstance(
            indexTheme = newIndexTheme;
        );
    }
}

I think this way works if you didn't try it before, now you can call this function to change all values

Related