showPicker static method

dynamic showPicker({
  1. required List<Widget> children,
  2. dynamic onConfirm(
    1. int selectIndex
    )?,
  3. dynamic onCancel()?,
  4. Widget? cancel,
  5. Widget? confirm,
  6. bool useSafeArea = false,
  7. double itemExtent = 30,
  8. int initialItem = 0,
  9. Widget selectionOverlay = const CupertinoPickerDefaultSelectionOverlay(),
})

Implementation

static showPicker(
    {required List<Widget> children,
    Function(int selectIndex)? onConfirm,
    Function()? onCancel,
    Widget? cancel,
    Widget? confirm,
    bool useSafeArea = false,
    double itemExtent = 30,
    int initialItem = 0,
    Widget selectionOverlay =
        const CupertinoPickerDefaultSelectionOverlay()}) {
  int selectIndex = initialItem;
  showModalBottomSheet(
    context: Get.context!,
    useSafeArea: useSafeArea,
    builder: (BuildContext context) => SizedBox(
      height: 300,
      child: Column(
        children: [
          Padding(
            padding: EdgeInsets.only(
                top: CommonStyle.spaceMd,
                left: CommonStyle.spaceLg,
                right: CommonStyle.spaceLg),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                GestureDetector(
                  onTap: onCancel ?? () => Get.back(),
                  child: cancel ??
                      Text(
                        "取消".tr,
                        style: Theme.of(context).textTheme.titleMedium,
                      ),
                ),
                GestureDetector(
                  onTap: () {
                    onConfirm?.call(selectIndex);
                    Get.back();
                  },
                  child: confirm ??
                      Text(
                        "确定".tr,
                        style: Theme.of(context)
                            .textTheme
                            .titleMedium
                            ?.copyWith(color: CommonColors.theme),
                      ),
                ),
              ],
            ),
          ),
          SizedBox(
            height: 250,
            child: CupertinoPicker(
              backgroundColor: Colors.transparent,
              itemExtent: itemExtent,
              onSelectedItemChanged: (int index) {
                selectIndex = index;
              },
              selectionOverlay: selectionOverlay,
              scrollController:
                  FixedExtentScrollController(initialItem: initialItem),
              children: children,
            ),
          ),
        ],
      ),
    ),
  );
}