我创建了一个选择器,它显示一个图标和一个字符串,彼此相邻。选择器项目取自我创建的包含键:字符串和值:图标的地图。
现在在我的代码中,我正在使用 Cupertino Picker 并添加子项:[ Row(Icon + String)] 但如果我想更新它们,那就太糟糕了。
我试图让一个循环来生成那些行+孩子,但我不知道怎么做。
有人可以告诉我获得这个结果的方法或者更有效的方法吗?我正在考虑提取行并创建一个构造函数来输入图标和字符串,但我确信有更好的方法......
这是代码:
Expanded(
child: CupertinoPicker(
itemExtent: 40,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[0],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[0],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[1],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[1],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[2],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[2],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[3],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[3],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[4],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[4],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[5],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[5],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[6],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[6],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[7],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[7],
style:
TextStyle(color: Colors.white70),
),
)
],
)
],
onSelectedItemChanged: (int index) {
print('good boi');
},
looping: true,
backgroundColor: Color(0xff2e3032),
),
),
它的样子: