simpleDatePicker static method

Future simpleDatePicker(
  1. BuildContext context, {
  2. bool barrierDismissible = true,
  3. double height = 500,
  4. double width = 400,
  5. int needYear = 110,
  6. double vGap = 16,
  7. BoxDecoration? pickerDecoration,
  8. DateModel? startDate,
  9. DateModel? endDate,
  10. double pickerVisibilityHeight = 140,
  11. double itemHeight = 40,
  12. double itemWidth = 100,
  13. double maskHeight = 40,
  14. double maskRadius = 0,
  15. int backwardYear = 50,
  16. Color? maskColor = const Color.fromRGBO(242, 242, 244, 0.7),
  17. Duration duration = const Duration(milliseconds: 500),
  18. Curve curve = Curves.easeInOutCubic,
  19. dynamic callBack(
    1. DateModel? startDate,
    2. DateModel? endDate
    )?,
})

展示选择器基础示例,不满足样式外部可自定义。

Implementation

static Future<dynamic> simpleDatePicker(
    BuildContext context,
    {bool barrierDismissible = true,
      double height = 500,
      double width = 400,
      int needYear = 110,
      double vGap = 16,
      BoxDecoration? pickerDecoration,
      DateModel? startDate,
      DateModel? endDate,
      double pickerVisibilityHeight = 140,
      double itemHeight = 40,
      double itemWidth = 100,
      double maskHeight = 40,
      double maskRadius = 0,
      int backwardYear = 50,
      Color? maskColor = const Color.fromRGBO(242, 242, 244, 0.7),
      Duration duration = const Duration(milliseconds: 500),
      Curve curve = Curves.easeInOutCubic,
      Function(DateModel? startDate, DateModel? endDate)? callBack}) {
  final  controller = DateController();
  return showDialog(
      context: context,
      barrierDismissible: barrierDismissible,
      builder: (context) {
        return DatePicker(
          controller: controller,
          pickerDecoration: pickerDecoration,
          width: width,
          height: height,
          needYear: needYear,
          startDate: startDate,
          endDate: endDate,
          backwardYear: backwardYear,
          vGap: vGap,
          pickerVisibilityHeight: pickerVisibilityHeight,
          itemHeight: itemHeight,
          itemWidth: itemWidth,
          maskHeight: maskHeight,
          maskRadius: maskRadius,
          maskColor: maskColor,
          duration: duration,
          curve: curve,
          startWidget: const Padding(
            padding: EdgeInsets.only(left: 20),
            child: Text('开始日期:',
                style: TextStyle(
                    color: Colors.black,
                    fontSize: 14,
                    fontWeight: FontWeight.bold)),
          ),
          endWidget: const Padding(
            padding: EdgeInsets.only(left: 20),
            child: Text('结束日期:',
                style: TextStyle(
                    color: Colors.black,
                    fontSize: 14,
                    fontWeight: FontWeight.bold)),
          ),
          yearBuilder: (year) {
            return Center(
              child: Text(
                "$year年",
                style: const TextStyle(
                    color: Color.fromRGBO(21, 21, 21, 1),
                    fontSize: 16,
                    fontWeight: FontWeight.bold)
              ),
            );
          },
          monthBuilder: (month) {
            return Container(
              alignment: Alignment.center,
              child: Text(
                "$month月",
                style: const TextStyle(
                    color: Color.fromRGBO(21, 21, 21, 1),
                    fontSize: 16,
                    fontWeight: FontWeight.bold)
              ),
            );
          },
          dayBuilder: (day) {
            return Container(
              alignment: Alignment.center,
              child: Text(
                "$day日",
                style: const TextStyle(
                    color: Color.fromRGBO(21, 21, 21, 1),
                    fontSize: 16,
                    fontWeight: FontWeight.bold)
              ),
            );
          },
          action: GestureDetector(
            onTap: () {
              final startDate = controller.getStartDate();
              final endDate = controller.getEndDate();
              callBack?.call(startDate, endDate);
              Navigator.pop(context, [startDate, endDate]);
            },
            child: Center(
                child: Container(
                  margin: const EdgeInsets.only(top: 30),
                  padding:
                  const EdgeInsets.symmetric(horizontal: 40, vertical: 10),
                  decoration: BoxDecoration(
                    color: Colors.lightBlueAccent,
                    borderRadius: BorderRadius.circular(20),
                  ),
                  child: const Text("确定",
                      style: TextStyle(color: Colors.white, fontSize: 16)),
                )),
          ),
        );
      });
}