首页 > 解决方案 > 未在颤动中显示年份下拉数据

问题描述

这是我的列表,用于显示字符串类型列表中的数据-

 List<Widget> _getYearList() {
    List<Widget> list = List<Widget>();

      for (int index = 0; index < 30; index++) {
        list.add(Container(
          alignment: Alignment.center,
          child: Text(
            UtilString.years[index],
            //'$index',
            style: TextStyle(fontSize: 16),
          ),
        ));
      }

      return list;

  }

这是设计视图-

SizedBox(width: 8),
                Text(
                  '${UtilString.year} : ',
                  style: TextStyle(
                    fontSize: 16,
                    color: Colors.grey[700],
                  ),
                ),
                Container(
                  height: 100,
                  width: 52,
                  child: CupertinoPicker(
                    squeeze: 1.3,
                    itemExtent: 30,
                    backgroundColor: Colors.white,
                    children: _getYearList(),
                    scrollController: FixedExtentScrollController(
                      initialItem: _year - 1,
                    ),
                    onSelectedItemChanged: (item) {
                      setState(() {
                        _year = item + 1;
                      });
                    },
                  ),
                ),
              ],
            ),

定义数据

static final List years = <String>['1990', '1991', '1992', '1993 till 2020];

标签: listflutterdropdown

解决方案


推荐阅读