123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'alert_dialog.dart';
- import 'custom_date_picker.dart';
- class _VDialogDateValueCache {
- DateTime value;
- _VDialogDateValueCache(this.value);
- }
- /// 弹窗日期选择器
- class VDialogDate extends StatelessWidget {
- /// 标题
- final String? title;
- /// 初始值
- final DateTime? initialValue;
- /// 最小时间
- final DateTime? minimumDate;
- /// 最大值
- final DateTime? maxValue;
- const VDialogDate({
- super.key,
- this.title,
- this.initialValue,
- this.minimumDate,
- this.maxValue,
- });
- Future<DateTime?> show<DateTime>() => VAlertDialog.showDialog<DateTime>(this);
- @override
- Widget build(BuildContext context) {
- DateTime initialDateTime = initialValue ?? DateTime.now();
- final valueCache = _VDialogDateValueCache(
- DateTime(
- initialDateTime.year,
- initialDateTime.month,
- initialDateTime.day,
- ),
- );
- return VAlertDialog(
- title: title,
- contentPadding: const EdgeInsets.symmetric(vertical: 0, horizontal: 16),
- content: _buildContent(context, valueCache),
- showCancel: true,
- onConfirm: () {
- Get.back(result: valueCache.value);
- },
- );
- }
- Widget _buildContent(BuildContext context, _VDialogDateValueCache cache) {
- // 不保留时间部分
- return Container(
- margin: const EdgeInsets.all(10),
- height: 216,
- // width: 460,
- child: Stack(
- children: [
- Positioned.fill(
- child: VCustomCupertinoDatePicker(
- initialDateTime: cache.value,
- minimumYear: 1900,
- maximumYear: 2100,
- minimumDate: minimumDate,
- maximumDate: maxValue,
- backgroundColor: CupertinoColors.white,
- onDateTimeChanged: (date) {
- cache.value = date;
- },
- ),
- ),
- Positioned(
- top: 72,
- left: 0,
- right: 0,
- child: Divider(
- thickness: 1,
- color: Colors.black.withOpacity(0.2),
- indent: 12,
- endIndent: 12,
- ),
- ),
- Positioned(
- top: 72 + 58,
- left: 0,
- right: 0,
- child: Divider(
- thickness: 1,
- color: Colors.black.withOpacity(0.2),
- indent: 12,
- endIndent: 12,
- ),
- ),
- ],
- ),
- );
- }
- }
|