99 lines
3.0 KiB
Dart
99 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import '../../constants/color_constant.dart';
|
|
import '../../utils/helper_function.dart';
|
|
|
|
class EnhancedDatePicker extends StatelessWidget {
|
|
final String label;
|
|
final String selectedDate;
|
|
final Function(BuildContext) onDatePicked;
|
|
final Color? fillColor;
|
|
final Color? borderColor;
|
|
final double? height;
|
|
|
|
const EnhancedDatePicker({
|
|
super.key,
|
|
required this.label,
|
|
required this.selectedDate,
|
|
required this.onDatePicked,
|
|
this.fillColor,
|
|
this.borderColor,
|
|
this.height,
|
|
});
|
|
|
|
String formatDateToYMD(dynamic date) {
|
|
try {
|
|
final parsed = date is DateTime ? date : DateTime.parse(date.toString());
|
|
return "${parsed.month.toString().padLeft(2, '0')}-${parsed.day.toString().padLeft(2, '0')}-${parsed.year.toString().padLeft(4, '0')}";
|
|
} catch (e) {
|
|
return "Invalid Date";
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
bool hasSelectedDate = selectedDate.isNotEmpty;
|
|
|
|
return GestureDetector(
|
|
onTap: () => onDatePicked(context),
|
|
child: Container(
|
|
height: hasSelectedDate ? height : 60.h,
|
|
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h),
|
|
decoration: BoxDecoration(
|
|
color: fillColor ?? textFieldFillColor,
|
|
borderRadius: BorderRadius.circular(10.r),
|
|
border: Border.all(
|
|
color: borderColor ?? textfieldBorderColorSky1,
|
|
width: 1,
|
|
),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
hasSelectedDate
|
|
? Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: (isTablet ? 11.sp : 14.sp),
|
|
fontWeight: FontWeight.w500,
|
|
color: greyTextColor1,
|
|
),
|
|
),
|
|
SizedBox(height: 4.h),
|
|
Text(
|
|
formatDateToYMD(selectedDate),
|
|
style: TextStyle(
|
|
fontSize: isTablet ? 14.sp : 16.sp,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.black,
|
|
),
|
|
),
|
|
],
|
|
)
|
|
: Expanded(
|
|
child: Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: isTablet ? 15.sp : 16.sp,
|
|
fontWeight: FontWeight.w500,
|
|
color: greyTextColor1,
|
|
),
|
|
),
|
|
),
|
|
Icon(
|
|
Icons.keyboard_arrow_down,
|
|
color: greyTextColor1,
|
|
size: isTablet ? 20.sp : 18.sp,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|