我是颤振开发方面的新手,我尝试在CupertinoPicker内部通过单击CupertinoButton触发。
在选择Provinsi (Province)之后,我可以通过再次单击按钮来重新启动Province,但是它应该是我选择的项目。
这是我的密码
showCupertinoModalPopup(
context: context,
builder: (_) {
return new SizedBox(
height: MediaQuery.of(context).size.height / 2,
child: new CupertinoPicker(
magnification: 1.2,
useMagnifier: true,
itemExtent: 32.0,
onSelectedItemChanged: (i) => setState(() => _chosenProvince = listProvince[i]),
children: r != null && listProvince != null ? listProvince.map((prov) {
return new Padding(
padding: const EdgeInsets.all(4.0),
child: new Text(
prov.name,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: new TextStyle(
fontSize: 20.0,
),
),
);
}).toList(): [],),);});是否有initialValue或CupertinoPicker设置的东西?
发布于 2018-09-18 13:31:06
可以使用FixedExtentScrollController设置initialValue。请参阅这
发布于 2020-01-09 19:06:04
正如Dinesh Balasubramanian所描述的,您可以使用FixedExtentScrollController设置initialValue
它将如下所示,例如从第四个元素开始:
showCupertinoModalPopup(
context: context,
builder: (_) {
return new SizedBox(
height: MediaQuery.of(context).size.height / 2,
child: new CupertinoPicker(
scrollController: FixedExtentScrollController(initialItem: 3),
magnification: 1.2,
useMagnifier: true,
itemExtent: 32.0,
onSelectedItemChanged: (i) => setState(() => _chosenProvince = listProvince[i]),
children: r != null && listProvince != null ? listProvince.map((prov) {
return new Padding(
padding: const EdgeInsets.all(4.0),
child: new Text(
prov.name,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: new TextStyle(
fontSize: 20.0,
),
),
);
}).toList(): [],),);});https://stackoverflow.com/questions/52385149
复制相似问题