简体   繁体   English

如何显示,在颤动的下拉列表中选择传递的值

[英]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;
                                
                              });
                            },
                          ),
                        ),

this is my _getYearList() method to show year dropdown这是我的 _getYearList() 方法来显示年份下拉列表

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.

相关问题 根据另一个下拉列表中的选定值限制日期 - Restrict date based on the selected value in another dropdown 如果使用数组,则在下拉列表中获取选定的月份值 - get selected month value in dropdown list if using an array 将日期的持续时间与选定的下拉值进行比较...请阅读 - Compare the duration of dates with selected dropdown value…read please 从同步日历抖动中获取选定日期的值数据 - Get value data form selected day from syncfution calendar flutter 从表日历 flutter 中获取选定日期的值数据表 - Get value data form selected day from table calendar flutter 当我使用 flutter 再次点击日期选择器时,我想在日期选择器中显示所选日期 - I wants to show selected date in date picker when I tap again on date picker using flutter 如何验证(和处理)传递给.to_date的值是否有效或返回错误? - How to validate (and handle) if value passed to .to_date is valid or returns error? 如何在下次调用时在DatePickerDialog中显示以前选择的日期? - How do I show the previously selected date in a DatePickerDialog on next call? 在jQuery中,如何根据从下拉列表中选择的月份增加年份 - In jQuery How Would You Increment the Year based on Month selected from a Dropdown 不应该选择的下拉选项 - Dropdown option getting selected when it should not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM