Implementation
filterBottomsheet(
BuildContext context,
final Function(String, String) onFilter, {
String? dateFormt,
}) async {
TextEditingController dateFromController = TextEditingController();
TextEditingController dateToController = TextEditingController();
final Localization localization = Localization.getInstance();
showModalBottomSheet(
elevation: 2,
isScrollControlled: true,
context: context,
backgroundColor: ColorConstant.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(SizeConstant.getHeightWithScreen(20)),
topRight: Radius.circular(SizeConstant.getHeightWithScreen(20))),
),
builder: (BuildContext ctx) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return Container(
width: double.maxFinite,
decoration: BoxDecoration(
color: ColorConstant.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(
SizeConstant.getHeightWithScreen(20),
),
topRight: Radius.circular(
SizeConstant.getHeightWithScreen(20),
),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(
left: SizeConstant.getHeightWithScreen(20),
right: SizeConstant.getHeightWithScreen(9),
top: SizeConstant.getHeightWithScreen(10),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
localization.translate("dateFilter"),
style: TextStyle(
color: ColorConstant.black.withOpacity(0.88),
fontSize: SizeConstant.largeFont,
fontWeight: FontWeight.w600),
),
GestureDetector(
onTap: () {
Get.back();
},
child: Icon(
Icons.close,
color: ColorConstant.grey11,
size: SizeConstant.getHeightWithScreen(27),
),
)
],
),
),
SizedBox(
height: SizeConstant.getHeightWithScreen(30),
),
Container(
margin: EdgeInsets.symmetric(
horizontal: SizeConstant.getHeightWithScreen(16),
),
decoration: BoxDecoration(
color: ColorConstant.white,
border: Border.all(
color: ColorConstant.tfDisabledBorderColor),
borderRadius: BorderRadius.all(
Radius.circular(SizeConstant.getHeightWithScreen(10)),
),
),
// height: SizeConstant.getHeightWithScreen(50),
width: double.maxFinite,
child: TextField(
controller: dateFromController,
style: TextStyle(
color: ColorConstant.black1,
fontSize: SizeConstant.mediumFont,
fontWeight: FontWeight.w500,
),
decoration: InputDecoration(
contentPadding:
const EdgeInsets.only(left: 15, right: 8, top: 16),
suffixIcon: Icon(
Icons.calendar_today_rounded,
color: ColorConstant.grey7,
),
// hintText: "fromDate".tr,
// hintStyle: TextStyle(
// color: ColorConstant.textFieldHintColor,
// fontSize: SizeConstant.smallFont,
// fontWeight: FontWeight.w400,
// ),
labelText: localization.translate("fromDate"),
labelStyle: TextStyle(
color: ColorConstant.textFieldHintColor,
fontSize: SizeConstant.smallFont,
fontWeight: FontWeight.w400,
),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
),
readOnly: true,
onTap: () async {
DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate:
DateTime.now().subtract(const Duration(days: 60)),
lastDate: DateTime.now(),
);
if (pickedDate != null) {
debugPrint(pickedDate.toString());
String formattedDate =
DateFormat(dateFormt ?? 'yyyy-MM-dd')
.format(pickedDate);
debugPrint(formattedDate);
setState(
() {
dateFromController.text = formattedDate;
},
);
// widget.onDateSelected(formattedDate);
} else {
debugPrint("Date is not selected");
}
},
),
),
SizedBox(
height: SizeConstant.getHeightWithScreen(20),
),
Container(
margin: EdgeInsets.symmetric(
horizontal: SizeConstant.getHeightWithScreen(16),
),
decoration: BoxDecoration(
color: ColorConstant.white,
border: Border.all(
color: ColorConstant.tfDisabledBorderColor),
borderRadius: BorderRadius.all(
Radius.circular(SizeConstant.getHeightWithScreen(10)),
),
),
// height: SizeConstant.getHeightWithScreen(50),
width: double.maxFinite,
child: TextField(
controller: dateToController,
style: TextStyle(
color: ColorConstant.black1,
fontSize: SizeConstant.mediumFont,
fontWeight: FontWeight.w500,
),
decoration: InputDecoration(
contentPadding:
const EdgeInsets.only(left: 15, right: 8, top: 16),
suffixIcon: Icon(
Icons.calendar_today_rounded,
color: ColorConstant.grey7,
),
// hintText: "toDate".tr,
// hintStyle: TextStyle(
// color: ColorConstant.textFieldHintColor,
// fontSize: SizeConstant.smallFont,
// fontWeight: FontWeight.w400,
// ),
labelText: localization.translate("toDate"),
labelStyle: TextStyle(
color: ColorConstant.textFieldHintColor,
fontSize: SizeConstant.smallFont,
fontWeight: FontWeight.w400,
),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
),
readOnly: true,
onTap: () async {
DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate:
DateTime.now().subtract(const Duration(days: 60)),
lastDate: DateTime.now(),
);
if (pickedDate != null) {
debugPrint(pickedDate.toString());
String formattedDate =
DateFormat(dateFormt ?? 'yyyy-MM-dd')
.format(pickedDate);
debugPrint(formattedDate);
setState(
() {
dateToController.text = formattedDate;
},
);
// widget.onDateSelected(formattedDate);
} else {
debugPrint("Date is not selected");
}
},
),
),
SizedBox(
height: SizeConstant.getHeightWithScreen(40),
),
Container(
margin: EdgeInsets.symmetric(
horizontal: SizeConstant.getHeightWithScreen(16),
),
child: VentasPrimaryButton(
borderRadius: 9,
btnHeight: 48,
onTap: (dateToController.text.isNotEmpty &&
dateToController.text.isNotEmpty)
? () {
Get.back();
onFilter(dateFromController.text,
dateToController.text);
}
: null,
label: localization.translate('filter'),
textColor: ColorConstant.white,
textSize: SizeConstant.mediumFont,
weight: FontWeight.w600,
),
),
SizedBox(
height: SizeConstant.getHeightWithScreen(10),
),
],
),
);
});
});
}