将参数发送到类,但该类是用数组包装的

  • 本文关键字:数组 包装 参数 flutter dart
  • 更新时间 :
  • 英文 :


所以我有一个用数组缩放的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;
);
}
}

我认为如果你以前没有尝试过这种方法,现在你可以调用这个函数来更改的所有值

最新更新