年份的选择组件,长相比较寒酸。可指定选择的日期范围、选中日期等,接收每份选中事件

相关组件

DayPicker MonthPicker

YearPicker基本使用

  1. <br />【selectedDate】 : 选中日期 【DateTime】<br />【firstDate】 : 最前日期限制 【DateTime】<br />【lastDate】 : 最后日期限制 【DateTime】<br />【onChanged】 : 点击回调 【Function(DateTime)】<br />![150.gif](https://cdn.nlark.com/yuque/0/2020/gif/326147/1589458405951-58672857-db21-49d7-aa57-c6aff4435ed7.gif#align=left&display=inline&height=316&margin=%5Bobject%20Object%5D&name=150.gif&originHeight=316&originWidth=224&size=80180&status=done&style=none&width=224)
import 'package:flutter/material.dart';
class CustomYearPicker extends StatefulWidget {
  @override
  _CustomYearPickerState createState() => _CustomYearPickerState();
}

class _CustomYearPickerState extends State<CustomYearPicker> {
  DateTime _date = DateTime.now();

  @override
  Widget build(BuildContext context) {
    return Container(
      height:150,
      child: YearPicker(
        selectedDate: _date,
        onChanged: (date) => setState(() => _date = date),
        firstDate: DateTime(2018),
        lastDate: DateTime(2030),
      ),
    );
  }
}