我有幾個城市,當我點擊一個特定的城市時,我希望下一頁顯示該城市的模型。由于每個城市都包含很多模型,我為城市中的每個模型都有一個單獨的類。
List<City> cities = City.fetchAll();
for (i = 0; i < cities.length; i ) {
if (cityID == cities[i].id) {
// returns 'Paris' when paris is clicked on
String city = cities[i].name;
}
}
// Then I want to call the class TestParis and fetch the the list from that model:
final test = TestParis.fetchAll();
// or it could be another city:
final test = TestMadrid.fetchAll();
//
final test = 'Test${city}'.toClass.fetchAll();
所以基本上轉換字串來初始化一個類。我怎樣才能做到這一點?
uj5u.com熱心網友回復:
在 Flutter 中不可能,因為在 flutter 中沒有反射......在 dart 中只有鏡像包......但在這里你只能構建一個帶有類似建構式的映射
final test = {
'TestParis' : TestParis.fetchAll
}['Test${city}'].call() ;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/403628.html
標籤:
