我想通過將以下變數分組到一個類中或使它們成為全域變數來將它們放入串列中......我如何將其放入串列中?是否可以將這些變數放在串列中?
下面的按鈕是本地保存的最喜歡的變數。它經常變化。
ex.favorite[索引]
bool favoriteButton_0_01_01 = false;
bool favoriteButton_0_01_02 = false;
bool favoriteButton_0_01_03 = false;
bool favoriteButton_0_01_04 = false;
bool favoriteButton_0_01_05 = false;
bool favoriteButton_0_01_06 = false;
bool favoriteButton_0_01_07 = false;
bool favoriteButton_0_01_08 = false;
bool favoriteButton_0_01_09 = false;
bool favoriteButton_0_01_10 = false;
bool favoriteButton_0_01_11 = false;
bool favoriteButton_0_01_12 = false;
bool favoriteButton_0_01_13 = false;
bool favoriteButton_0_01_14 = false;
bool favoriteButton_0_01_15 = false;
bool favoriteButton_0_01_16 = false;
bool favoriteButton_0_01_17 = false;
bool favoriteButton_0_01_18 = false;
bool favoriteButton_0_01_19 = false;
bool favoriteButton_0_01_20 = false;
bool favoriteButton_0_01_21 = false;
bool favoriteButton_0_01_22 = false;
bool favoriteButton_0_01_23 = false;
bool favoriteButton_0_01_24 = false;
bool favoriteButton_0_01_25 = false;
bool favoriteButton_0_01_26 = false;
bool favoriteButton_0_01_27 = false;
bool favoriteButton_0_01_28 = false;
bool favoriteButton_0_01_29 = false;
bool favoriteButton_0_01_30 = false;
uj5u.com熱心網友回復:
用一個 List
List<bool> favoriteButtons = [
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
];
或者更好:
List<bool> favoriteButtons = List.filled(30, false);
像這樣使用它:
var buttonValue = favoriteButtons[3]; // Or whatever index
uj5u.com熱心網友回復:
您應該Map按照?? ???? ???? 的建議
使用,然后使用favorites.values.toList()[index]
Map<String, bool> favorites = {
'favoriteButton_0_01_01': false,
'favoriteButton_0_01_02': false
};
print(favorites.values.toList()[0]);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/350640.html
