cupertinoselector static method

Future cupertinoselector({
  1. required BuildContext context,
  2. required dynamic title,
  3. required dynamic onChanged(
    1. int index,
    2. String value
    ),
  4. required Rx<Selection> selectionList,
  5. bool looping = false,
})

Implementation

static Future cupertinoselector({
  required BuildContext context,
  required title,
  required Function(int index, String value) onChanged,
  required Rx<Selection> selectionList,
  bool looping = false,
}) {
  if (selectionList.value.list == null) {
    selectionList.value.list!.insert(
      0,
      Select(selectID: 0, title: title, value: title),
    );
  } else if (selectionList.value.list![0].title.toString() != title) {
    selectionList.value.list!.insert(
      0,
      Select(selectID: 0, title: title, value: title),
    );
  }

  var selectedItemID = 0.obs;
  var selectedItem = selectionList.value.list![0].title.obs;

  return showCupertinoModalPopup(
    // barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return Container(
        height: 250,
        width: ARMOYU.screenWidth,
        color: Get.theme.scaffoldBackgroundColor,
        child: Column(
          children: [
            Align(
              alignment: Alignment.centerRight,
              child: GestureDetector(
                onTap: () {
                  onChanged(selectedItemID.value - 1, selectedItem.value);

                  Navigator.pop(context);
                },
                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: ARMOYU.screenWidth,
                  height: 200,
                  child: CupertinoPicker(
                    looping: looping,
                    itemExtent: 32,
                    children: List.generate(selectionList.value.list!.length,
                        (index) {
                      return Text(
                        selectionList.value.list![index].title.toString(),
                        style: index == 0
                            ? const TextStyle(color: Colors.grey)
                            : null,
                      );
                    }),
                    onSelectedItemChanged: (value) {
                      //
                      selectedItemID.value = value;
                      selectedItem.value =
                          selectionList.value.list![value].title.toString();
                      //
                      onChanged(selectedItemID.value - 1, selectedItem.value);
                    },
                  ),
                ),
              ],
            ),
          ],
        ),
      );
    },
  );
}