[英]How to show, passed value be selected in dropdown in flutter
in flutter code initial item how I pass same year which I getting in _year value in the dropdown as selected ========================================================================在颤振代码初始项目中,我如何通过同一年,我在下拉列表中获得了 _year 值作为选择 ============================== ============================================
Container(
height: 100,
width: 48,
child: CupertinoPicker(
squeeze: 1.3,
itemExtent: 30,
backgroundColor: Colors.white,
children: _getYearList(),
scrollController: FixedExtentScrollController(
initialItem: DateTime.now().year.compareTo(_year),
),
onSelectedItemChanged: (item) {
setState(() {
_year = DateTime.now().year - 30 + item;
});
},
),
),
List<Widget> _getYearList() {
List list = new List<Widget>();
int currentYear = DateTime.now().year - 30;
print("yearrr : " + currentYear.toString());
list.contains(_year);
_year.compareTo(currentYear);
print("currentYear :" + currentYear.toString());
//for (int index = currentYear; index <= currentYear + 30; index++) {
for (int index = currentYear; index <= currentYear + 30; index++) {
list.add(Container(
alignment: Alignment.center,
child: Text(
'$index',
//'$index - ${index + 1}',
style: TextStyle(fontSize: 16),
),
));
}
return list;
}
If I got the question right... The way to identify the value change in CupertinoPicker/DropdownButton is the callback function of onSelectedItemChanged/onChanged which is used in your code.如果我的问题是正确的... 识别 CupertinoPicker/DropdownButton 中值更改的方法是您的代码中使用的 onSelectedItemChanged/onChanged 的回调函数。 The callback function has an argument
void Function(T value)
which is the selected value.回调函数有一个参数
void Function(T value)
,它是选定的值。 You can have a member of T type and keep there changed value in case of onSelectedItemChanged/onChanged via setState(){...}.您可以拥有 T 类型的成员,并通过 setState(){...} 在 onSelectedItemChanged/onChanged 的情况下保留更改的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.