Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -83,38 +83,44 @@ class _CalendarChooseWidgetState extends State<CalendarChooseWidget> {
|
||||
String get dealTimeString {
|
||||
String? time = "";
|
||||
if (endTime == null) {
|
||||
time = DateTimeUtils.dateTimeUtilsTool(
|
||||
dateTime: startTime.toString(),
|
||||
dateTimeUtilsType:
|
||||
widget.dateTimeUtilsType ?? DateTimeUtilsType.yearMonthDay,
|
||||
);
|
||||
time = _formatDisplayDate(startTime);
|
||||
} else if (endTime == startTime) {
|
||||
time = DateTimeUtils.dateTimeUtilsTool(
|
||||
dateTime: startTime.toString(),
|
||||
dateTimeUtilsType:
|
||||
widget.dateTimeUtilsType ?? DateTimeUtilsType.yearMonthDay,
|
||||
);
|
||||
time = _formatDisplayDate(startTime);
|
||||
} else {
|
||||
time = "${DateTimeUtils.dateTimeUtilsTool(
|
||||
dateTime: startTime.toString(),
|
||||
dateTimeUtilsType:
|
||||
widget.dateTimeUtilsType ?? DateTimeUtilsType.yearMonthDay,
|
||||
)} - ${DateTimeUtils.dateTimeUtilsTool(
|
||||
dateTime: endTime.toString(),
|
||||
dateTimeUtilsType:
|
||||
widget.dateTimeUtilsType ?? DateTimeUtilsType.yearMonthDay,
|
||||
)}";
|
||||
time =
|
||||
"${_formatDisplayDate(startTime)} - ${_formatDisplayDate(endTime)}";
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
String _formatDisplayDate(DateTime? dateTime) {
|
||||
if (dateTime == null) {
|
||||
return '-- --';
|
||||
}
|
||||
final dateType = widget.dateTimeUtilsType ?? DateTimeUtilsType.yearMonthDay;
|
||||
final formatted = DateTimeUtils.dateTimeUtilsTool(
|
||||
dateTime: dateTime.toString(),
|
||||
dateTimeUtilsType: dateType,
|
||||
);
|
||||
if (widget.chooseIndex == 1 &&
|
||||
dateType == DateTimeUtilsType.yearMonthDayWord) {
|
||||
return '$formatted ${DateTimeUtils.getWeekDay(dateTime)}';
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
|
||||
///日历弹窗
|
||||
onTapDate() {
|
||||
final screenHeight = MediaQuery.of(context).size.height;
|
||||
final singlePickerHeight =
|
||||
screenHeight * 0.5 < 420 ? 420.0 : screenHeight * 0.5;
|
||||
final rangePickerHeight =
|
||||
screenHeight * 0.5 < 460 ? 460.0 : screenHeight * 0.5;
|
||||
if (widget.chooseIndex == 1) {
|
||||
ToastUtils.showBottomSheet(
|
||||
context: context,
|
||||
title: '选择时间',
|
||||
height: MediaQuery.of(context).size.height / 2,
|
||||
height: singlePickerHeight,
|
||||
isShowConfirm: true,
|
||||
contentWidget: CustomDatePicker(
|
||||
initialDate: DateTime.now(),
|
||||
@@ -131,7 +137,7 @@ class _CalendarChooseWidgetState extends State<CalendarChooseWidget> {
|
||||
ToastUtils.showBottomSheet(
|
||||
context: context,
|
||||
title: '选择时间',
|
||||
height: MediaQuery.of(context).size.height / 2,
|
||||
height: rangePickerHeight,
|
||||
isShowConfirm: true,
|
||||
contentWidget: CustomCalendarRangePickerWidget(
|
||||
firstDate: DateTime(DateTime.now().year - 2),
|
||||
|
||||
@@ -867,6 +867,7 @@ class _DayHeaders extends StatelessWidget {
|
||||
),
|
||||
child: GridView.custom(
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.zero,
|
||||
gridDelegate: _monthItemGridDelegate,
|
||||
childrenDelegate: SliverChildListDelegate(
|
||||
labels,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/// A Calculator.
|
||||
class Calculator {
|
||||
/// Returns [value] plus 1.
|
||||
int addOne(int value) => value + 1;
|
||||
}
|
||||
library flutter_common;
|
||||
|
||||
export 'calendarcalendar/calendar_choose_widget.dart';
|
||||
export 'calendarcalendar/custom_calendar_range_picker_widget.dart';
|
||||
export 'calendarcalendar/custom_date_picker.dart';
|
||||
export 'utils/date_utils.dart';
|
||||
|
||||
@@ -59,100 +59,113 @@ class ToastUtils {
|
||||
bool isShowConfirm = false,
|
||||
Color? barrierColor,
|
||||
EdgeInsetsGeometry? padding,
|
||||
bool useSafeArea = true,
|
||||
bool useSafeArea = false,
|
||||
}) {
|
||||
cancelToast();
|
||||
return showDialog(
|
||||
useSafeArea: useSafeArea,
|
||||
context: context,
|
||||
builder: (BuildContext ctx) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
height: MediaQuery.of(context).size.height / 2,
|
||||
margin: EdgeInsets.only(
|
||||
top: height == null
|
||||
? MediaQuery.of(context).size.height / 2
|
||||
: (MediaQuery.of(context).size.height - height),
|
||||
),
|
||||
padding: padding ?? const EdgeInsets.only(bottom: 40),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(12),
|
||||
topRight: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
header ??
|
||||
Container(
|
||||
padding: const EdgeInsets.only(bottom: 5),
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom:
|
||||
BorderSide(color: Color(0xffE1E1E1), width: 0.5),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
final dialogHeight = height ?? MediaQuery.of(ctx).size.height / 2;
|
||||
return Material(
|
||||
type: MaterialType.transparency,
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(12),
|
||||
topRight: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: SizedBox(
|
||||
height: dialogHeight,
|
||||
child: Padding(
|
||||
padding: padding ?? EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
child: Container(
|
||||
padding:
|
||||
const EdgeInsets.only(left: 6, right: 10),
|
||||
color: Colors.transparent,
|
||||
child: Icon(
|
||||
Icons.keyboard_arrow_down_rounded,
|
||||
size: leftIconSize ?? 40,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
title ?? '头部',
|
||||
style: TextStyle(
|
||||
color: const Color(0xff333333),
|
||||
fontSize: titleFontSize ?? 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
header ??
|
||||
Container(
|
||||
padding: const EdgeInsets.only(bottom: 5),
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: Color(0xffE1E1E1),
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(ctx).pop(),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 6,
|
||||
right: 10,
|
||||
),
|
||||
color: Colors.transparent,
|
||||
child: Icon(
|
||||
Icons.keyboard_arrow_down_rounded,
|
||||
size: leftIconSize ?? 40,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
title ?? '头部',
|
||||
style: TextStyle(
|
||||
color: const Color(0xff333333),
|
||||
fontSize: titleFontSize ?? 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (isShowConfirm) {
|
||||
if (onConfirm != null) {
|
||||
onConfirm();
|
||||
Navigator.of(ctx).pop();
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 10,
|
||||
top: 8,
|
||||
bottom: 8,
|
||||
right: 18,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
color: Colors.transparent,
|
||||
child: Text(
|
||||
'确定',
|
||||
style: TextStyle(
|
||||
color: isShowConfirm
|
||||
? const Color(0xff4D6FD5)
|
||||
: Colors.transparent,
|
||||
fontSize: 16),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (isShowConfirm) {
|
||||
if (onConfirm != null) {
|
||||
onConfirm();
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 10,
|
||||
top: 8,
|
||||
bottom: 8,
|
||||
right: 18,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
color: Colors.transparent,
|
||||
child: Text(
|
||||
'确定',
|
||||
style: TextStyle(
|
||||
color: isShowConfirm
|
||||
? const Color(0xff4D6FD5)
|
||||
: Colors.transparent,
|
||||
fontSize: 16),
|
||||
),
|
||||
),
|
||||
)
|
||||
Expanded(child: contentWidget ?? const SizedBox())
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(child: contentWidget ?? const SizedBox())
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user