所以我有一个用数组缩放的screenData
包装的类,我想把indexTheme
传递给这些类中的每一个。
int indexTheme = 1;
final screenData = [
const homeTest(),
const productPage(),
const trading(),
const inventoryPage(),
const masterPage(),
const financePage(),
];
我可以简单地像这样传递数据,但将来我想更改int的值。
int indexTheme = 1;
const homeTest(
indexTheme = 1;
),
您可以使用for循环来传递参数
Void changeIndexTheme(int newIndexTheme){
for(var classInstance in screenData){ //instead of var it's better to write your class name
classInstance(
indexTheme = newIndexTheme;
);
}
}
我认为如果你以前没有尝试过这种方法,现在你可以调用这个函数来更改的所有值