showDatePicker static method

dynamic showDatePicker({
  1. dynamic onConfirm(
    1. DateTime date
    )?,
  2. dynamic onCancel()?,
  3. Widget? cancel,
  4. Widget? confirm,
  5. bool useSafeArea = false,
})

Implementation

static showDatePicker({
  Function(DateTime date)? onConfirm,
  Function()? onCancel,
  Widget? cancel,
  Widget? confirm,
  bool useSafeArea = false,
}) {
  DateTime date = DateTime.now();
  showModalBottomSheet(
    context: Get.context!,
    useSafeArea: useSafeArea,
    builder: (BuildContext context) => SizedBox(
      height: 300,
      child: Column(
        children: [
          Padding(
            padding: EdgeInsets.only(
                top: CommonStyle.spaceMd,
                left: CommonStyle.spaceLg,
                right: CommonStyle.spaceLg),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                GestureDetector(
                  onTap: onCancel ?? () => Get.back(),
                  child: cancel ??
                      Text(
                        "取消".tr,
                        style: Theme.of(context).textTheme.titleMedium,
                      ),
                ),
                GestureDetector(
                  onTap: () {
                    onConfirm?.call(date);
                    Get.back();
                  },
                  child: confirm ??
                      Text(
                        "确定".tr,
                        style: Theme.of(context)
                            .textTheme
                            .titleMedium
                            ?.copyWith(color: CommonColors.theme),
                      ),
                ),
              ],
            ),
          ),
          SizedBox(
            height: 250,
            child: CupertinoDatePicker(
                mode: CupertinoDatePickerMode.date,
                onDateTimeChanged: (DateTime newDate) {
                  date = newDate;
                }),
          )
        ],
      ),
    ),
  );
}