flutter - 在列表之间切换时,动态多级 CupertinoPicker 会倾斜第一个文本项的对齐方式
问题描述
我正在尝试创建一个动态的多级 CupertinoPicker。当您从第一个列表中选择位置类型时,它会显示与该类型匹配的位置列表。这部分工作正常,问题是如果我切换到不同的位置列表,第二个位置列表的第一个 Text 小部件会根据第一个位置列表的第一个 Text 小部件缩进。
我尝试使用“对齐:TextAlignment.center”指定文本小部件应与中心对齐。在位置列表之间交换时,我还尝试将位置设置为空。这些都没有解决问题,也没有任何明显的效果。
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(bottom: 5.0),
height: pickerHeight,
width: logicalSize.width,
child: CupertinoPicker(
backgroundColor: Colors.white,
itemExtent: 32.0,
onSelectedItemChanged: (selectedIndex) {
setState(() {
location = null;
locationType = locationTypeList[selectedIndex];
});
},
children: pickerLocationType,
),
),
Container(
height: pickerHeight,
width: logicalSize.width,
child: CupertinoPicker(
backgroundColor: Colors.white,
itemExtent: 30.0,
onSelectedItemChanged: (selectedIndex) {
setState(() {
location = null;
if (locationType == 'Campus') {
location = campusList[selectedIndex];
}
if (locationType == 'City') {
location = cityList[selectedIndex];
}
});
},
children: pickerMap[locationType],
),
),
结果应该是第一行是(想象这个集合成一个 CupertinoPicker):
----------------------------------城市1-------------- ----------------------
----------------------------------城市2-------------- ----------------------
但它看起来更像:
-------------------------------------------城市 1----------------- ----------------------
----------------------------------城市2-------------- ----------------------
如果需要图片,我将使用它们的链接编辑这篇文章。
解决方案
我发现了解决方案。见下文:
Container(
key: ValueKey(this._locationType),
height: pickerHeight,
width: logicalSize.width,
child: CupertinoPicker(
backgroundColor: Colors.white,
itemExtent: 30.0,
onSelectedItemChanged: (selectedIndex) {
setState(() {
location = null;
if (locationType == 'Campus') {
location = campusList[selectedIndex];
}
if (locationType == 'City') {
location = cityList[selectedIndex];
}
});
},
children: pickerMap[locationType],
),
),
推荐阅读
- mysql - DATEDIFF(YEAR,C.END_DT,GETDATE()) 的 MySQL Workbench 版本是什么?
- python - 如何获取图像并将其加载到与图像名称相同的变量名称中
- php - 使用 fopen 创建文件
- kubernetes - 如何更新本地 Kubernetes API 服务器以使用 Dex 启用 OIDC?
- node.js - 部署到 Heroku 的 Nodejs Ionic-Angular 仅显示后端,而不是启动整个应用程序
- c# - LangageExt:使用 Bind() 链接两个 Either,但无法弄清楚如何使用它们创建另一个 Either
- java - 向python套接字服务器发送消息
- informatica - 从 informatica 调用存储的包
- anaconda - 如何找出橙色数据集中列中的唯一值和唯一值的数量?
- react-native - 运行测试时反应原生 customBubblingEventTypes 错误