onufitness_mobile/lib/widgets/pickers/custom_date_picker.dart
2026-01-13 11:36:24 +05:30

87 lines
2.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:onufitness/constants/color_constant.dart';
import 'package:onufitness/utils/helper_function.dart';
class CustomDatePicker extends StatelessWidget {
final String label;
final String selectedDate;
final Function(BuildContext) onDatePicked;
final Color? fillColor;
final Color? borderColor;
final double? height;
const CustomDatePicker({
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) {
return GestureDetector(
onTap: () => onDatePicked(context),
child: Container(
height: height,
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 14.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: [
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(
selectedDate.isNotEmpty
? formatDateToYMD(selectedDate)
: "Select Date",
style: TextStyle(
fontSize: isTablet ? 14.sp : 16.sp,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
],
),
Icon(
Icons.calendar_today_outlined,
color: greyTextColor1,
size: isTablet ? 20.sp : 18.sp,
),
],
),
),
);
}
}