【发布时间】:2021-09-10 10:03:59
【问题描述】:
我想将此列表字符串转换为列表状态小部件
List<String> listString = [
"HomePage()",
"ProfilePage()"
]
到
List<StatefulWidget> listStatefulWidget = [];
预期结果:
List<StatefulWidget> listStatefulWidget = [
HomePage(),
ProfilePage()
];
更新:
我需要一个需要 StatefulWidget 列表的导航栏。 tabs 是 StatefulWidget 的列表,应该从 API 获取值。我的 API 返回 listString,所以我需要将其转换为 statefulWidget。
这是我的代码:
var tabs<StatefulWidget> = [
HomePageView()
AccountView(),
];
return Scaffold(
key: scaffoldKey,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
bottomNavigationBar: CurvedNavigationBar(
key: _bottomNavigationKey,
index: 0,
height: 65.0,
items: [
//navbar
],
color: Colors.white,
buttonBackgroundColor: kSecondaryColor,
backgroundColor: Colors.transparent,
animationCurve: Curves.easeInOutQuint,
animationDuration: Duration(milliseconds: 300),
onTap: (index) {
setState(() {
_page = index;
});
},
letIndexChange: (index) => true,
),
body: tabs[_page]);
}
【问题讨论】:
-
你想达到什么目的?
-
@NishuthanS 很快我从 API 获得了字符串列表(例如:“HomePage()”)。然后我想将它转换为用于导航到底部导航栏中的每个类的 StatefulWidget