138 lines
4.4 KiB
Dart
138 lines
4.4 KiB
Dart
import 'package:common_utils/common_utils.dart';
|
|
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:forui/forui.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:syncfusion_flutter_datepicker/datepicker.dart';
|
|
|
|
import 'package:pj_supermarket_cloud/common/index.dart';
|
|
|
|
Widget appDatePicker(
|
|
BuildContext context, {
|
|
required Function(List<DateTime>?) onChnage,
|
|
required List<DateTime>? datetimeRange,
|
|
}) {
|
|
String detail = "请选择";
|
|
if (!ObjectUtil.isEmpty(datetimeRange)) {
|
|
final sartStr = DateUtil.formatDate(
|
|
datetimeRange![0],
|
|
format: DateFormats.y_mo_d,
|
|
);
|
|
final endStr = DateUtil.formatDate(
|
|
datetimeRange[1],
|
|
format: DateFormats.y_mo_d,
|
|
);
|
|
detail = "$sartStr-$endStr";
|
|
}
|
|
return TerminalToolbarDateControl(
|
|
label: detail,
|
|
showChevron: true,
|
|
onTap: () async {
|
|
final result = await appShowDatePicker(
|
|
context,
|
|
datetimeRange: datetimeRange,
|
|
);
|
|
onChnage(result);
|
|
},
|
|
);
|
|
}
|
|
|
|
Future<List<DateTime>?> appShowDatePicker(
|
|
BuildContext context, {
|
|
List<DateTime>? datetimeRange,
|
|
}) async {
|
|
final theme = FTheme.of(context);
|
|
final width = context.width;
|
|
final height = context.height;
|
|
// 默认时间为当天
|
|
DateTime startTIme = DateTime.now();
|
|
DateTime endTime = DateTime.now().add(const Duration(days: 1));
|
|
if (!ObjectUtil.isEmptyList(datetimeRange)) {
|
|
startTIme = datetimeRange![0];
|
|
endTime = datetimeRange[1];
|
|
}
|
|
List<DateTime> slectDateTime = [];
|
|
return showAppDialog<List<DateTime>?>(
|
|
context: context,
|
|
builder: (dialogContext) => AppDialog(
|
|
title: const Text('选择日期范围'),
|
|
width: width * 0.6,
|
|
maxWidth: width * 0.6,
|
|
onClose: () => Navigator.of(dialogContext).pop(null),
|
|
content: SfDateRangePicker(
|
|
onSelectionChanged: (date) {
|
|
if (date.value is PickerDateRange) {
|
|
final v = date.value as PickerDateRange;
|
|
if (v.startDate == null || v.endDate == null) {
|
|
return;
|
|
}
|
|
slectDateTime = [v.startDate!, v.endDate!];
|
|
}
|
|
},
|
|
initialSelectedDates: [startTIme, endTime],
|
|
selectionMode: DateRangePickerSelectionMode.range,
|
|
headerHeight: 60.h,
|
|
todayHighlightColor: theme.colorScheme.primary,
|
|
backgroundColor: theme.colorScheme.background,
|
|
headerStyle: DateRangePickerHeaderStyle(
|
|
textStyle: theme.typography.xl,
|
|
textAlign: TextAlign.center,
|
|
backgroundColor: theme.colorScheme.background,
|
|
),
|
|
selectionColor: theme.colorScheme.primary,
|
|
startRangeSelectionColor: theme.colorScheme.primary,
|
|
endRangeSelectionColor: theme.colorScheme.primary,
|
|
rangeSelectionColor: theme.colorScheme.mutedForeground,
|
|
selectionTextStyle: theme.typography.sm.copyWith(
|
|
color: theme.colorScheme.secondary,
|
|
),
|
|
rangeTextStyle: theme.typography.sm,
|
|
monthCellStyle: DateRangePickerMonthCellStyle(
|
|
textStyle: theme.typography.sm,
|
|
todayTextStyle: theme.typography.sm,
|
|
weekendTextStyle: theme.typography.sm,
|
|
),
|
|
monthViewSettings: DateRangePickerMonthViewSettings(
|
|
viewHeaderHeight: 50.h,
|
|
showWeekNumber: true,
|
|
weekNumberStyle: DateRangePickerWeekNumberStyle(
|
|
textStyle: theme.typography.sm,
|
|
backgroundColor: theme.colorScheme.mutedForeground,
|
|
),
|
|
viewHeaderStyle: DateRangePickerViewHeaderStyle(
|
|
textStyle: theme.typography.base,
|
|
),
|
|
),
|
|
).width(double.infinity).height(height * 0.6),
|
|
actions: [
|
|
FButton(
|
|
label: Text(
|
|
"确定",
|
|
style: theme.typography.xl.copyWith(
|
|
color: theme.colorScheme.secondary,
|
|
),
|
|
),
|
|
onPress: () {
|
|
if (ObjectUtil.isEmptyList(slectDateTime)) {
|
|
Toast.error(msg: "请选择日期范围");
|
|
return;
|
|
}
|
|
Navigator.of(dialogContext).pop(slectDateTime);
|
|
},
|
|
).width(300.w),
|
|
SizedBox(width: 30.w),
|
|
FButton(
|
|
style: FButtonStyle.destructive,
|
|
label: Text(
|
|
"取消",
|
|
style: theme.typography.xl.copyWith(
|
|
color: theme.colorScheme.secondary,
|
|
),
|
|
),
|
|
onPress: () => Navigator.of(dialogContext).pop(null),
|
|
).width(300.w),
|
|
],
|
|
),
|
|
);
|
|
}
|