cupertinoTimepicker static method
Future
cupertinoTimepicker(
{ - required dynamic onChanged(
- String
),
})
Implementation
static Future cupertinoTimepicker({
required Function(String) onChanged,
}) {
var hour = "00".obs;
var minute = "00".obs;
var selectedTime = "${hour.value}:${minute.value}".obs;
return showCupertinoModalPopup(
// barrierDismissible: false,
context: Get.context!,
builder: (BuildContext context) {
var hourList =
List.generate(24, (index) => {index: (index).toString()}).obs;
var minuteList =
List.generate(60, (index) => {index: (index).toString()}).obs;
if (hour.value.length == 1) {
hour.value = "0$hour";
}
if (minute.value.length == 1) {
minute.value = "0$minute";
}
return Container(
height: 250,
width: ARMOYU.screenWidth,
color: Get.theme.scaffoldBackgroundColor,
child: Column(
children: [
Align(
alignment: Alignment.centerRight,
child: GestureDetector(
onTap: () {
onChanged(selectedTime.value);
Get.back();
},
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"Bitti",
style: TextStyle(
color: Colors.lightBlue,
fontSize: 18,
fontWeight: FontWeight.normal,
decoration: TextDecoration.none,
),
),
),
),
),
Row(
children: [
SizedBox(
width: Get.width / 2,
height: 200,
child: CupertinoPicker(
looping: true,
itemExtent: 32,
children: List.generate(
hourList.length,
(index) {
Map<int, String> hourMap = hourList[index];
if (hourMap.values.last.length == 1) {
return Text("0${hourMap.values.last.toString()}");
} else {
return Text(hourMap.values.last.toString());
}
},
),
onSelectedItemChanged: (value) {
hour.value = hourList[value].values.first;
selectedTime.value = "${hour.value}:${minute.value}";
onChanged(selectedTime.value);
},
),
),
SizedBox(
width: Get.width / 2,
height: 150,
child: CupertinoPicker(
looping: true,
itemExtent: 32,
children: List.generate(minuteList.length, (index) {
Map<int, String> monthMap = minuteList[index];
if (monthMap.values.last.length == 1) {
return Text("0${monthMap.values.last.toString()}");
} else {
return Text(monthMap.values.last.toString());
}
}),
onSelectedItemChanged: (value) {
minute.value = minuteList[value].values.first;
selectedTime.value = "${hour.value}:${minute.value}";
onChanged(selectedTime.value);
},
),
),
],
),
],
),
);
},
);
}