showDateDialog static method

void showDateDialog(
  1. BuildContext context, {
  2. DateTime? startDate,
  3. DateTime? endDate,
  4. bool onClickOutSide = false,
  5. dynamic callBack(
    1. DateTime startTime,
    2. DateTime endTime
    )?,
  6. dynamic closeCallBack()?,
  7. double? aspectRatio,
  8. bool? allowSameDate = true,
})

startDate 默认选中日历的开始日期 endDate 默认选中日历的结束日期 onClickOutSide 点击非日历区域是否关闭 Function 选择日期后的回调 aspectRatio 添加宽高比,设置的calendarHeight将失效。

Implementation

static void showDateDialog(BuildContext context,
    {
      DateTime? startDate,
      DateTime? endDate,
      bool onClickOutSide = false,
      Function(DateTime startTime,
      DateTime endTime)? callBack,
      Function()? closeCallBack,
      double? aspectRatio,
      bool? allowSameDate = true,
    }) {

  showDialog<dynamic>(
      context: context,
      builder: (context) {
        return Material(
          type: MaterialType.transparency,
          child: GestureDetector(
            onTap: (){
              if(onClickOutSide){
                Navigator.of(context).pop();
              }
            },
            behavior: HitTestBehavior.opaque,
            child:Center(child:
            aspectRatio==null?SizedBox(
              height: getConfig().calendarHeight,
              width: getConfig().calendarWidth,
              child: CalendarPopupView(
                calendarConfig: getConfig(),
                barrierDismissible: onClickOutSide,
                minimumDate: getConfig().maximumDate,
                maximumDate: getConfig().maximumDate,
                initialEndDate: endDate,
                initialStartDate: startDate,
                allowSameDate: allowSameDate,
                onApplyClick: (DateTime startData, DateTime endData) {
                  if(null!=callBack){
                    callBack.call(startData,endData);
                  }
                },
                onCancelClick: () {
                  closeCallBack?.call();
                },
              ),
            ):
             SizedBox(
               width: getConfig().calendarWidth,
               child: AspectRatio(
                 aspectRatio: aspectRatio,
                 child: CalendarPopupView(
                   calendarConfig: getConfig(),
                   barrierDismissible: onClickOutSide,
                   minimumDate: getConfig().maximumDate,
                   maximumDate: getConfig().maximumDate,
                   initialEndDate: endDate,
                   initialStartDate: startDate,
                   allowSameDate: allowSameDate,
                   onApplyClick: (DateTime startData, DateTime endData) {
                     if(null!=callBack){
                       callBack.call(startData,endData);
                     }
                   },
                   onCancelClick: () {
                     closeCallBack?.call();
                   },
                 ),
               ),
             )),
          ),
        );
      },
  );
}