import 'package:flutter/material.dart'; import 'package:flutter_picker/flutter_picker.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; ///2023/7/17 ///底部弹出选择器工具类 typedef StringClickCallback = void Function(int selectIndex, Object selectStr); typedef ArrayClickCallback = void Function(List selecteds, List strData); typedef DateClickCallback = void Function(dynamic selectDateStr, dynamic selectDate); class ShowBottomSheetTool { ShowBottomSheetTool({ this.pickerHeight = 200.0, this.itemHeight = 45.0, this.btnColor = Colors.black, this.titleColor = const Color.fromRGBO(127, 127, 127, 1.0), this.textFontSize = 16.0 }); //选择器的高度 double pickerHeight; //单行的高度 double itemHeight; //按钮颜色 Color btnColor; //文本颜色 Color titleColor; //字体大小 double textFontSize; ///单列 void showSingleRowPicker( BuildContext context, { required List data, String? title, String? cancelTitle, String? sureTitle, int? normalIndex, PickerDataAdapter? adapter, required StringClickCallback clickCallBack, }) { openPicker(context, title: title!, cancelTitle: cancelTitle!, sureTitle: sureTitle!, selecteds: [normalIndex ?? 0], adapter: adapter ?? PickerDataAdapter(pickerData: data, isArray: false), clickCallBack: (Picker picker, List selecteds) { clickCallBack(selecteds[0], data[selecteds[0]] as Object); }); } ///多列 void showArrayPicker( BuildContext context, { required List data, String? title, List? normalIndex, PickerDataAdapter? adapter, required ArrayClickCallback clickCallBack, }) { openPicker(context, selecteds: normalIndex!, title: title!, adapter: adapter ?? PickerDataAdapter(pickerData: data, isArray: true), clickCallBack: (Picker picker, List selecteds) { clickCallBack(selecteds, picker.getSelectedValues()); }); } void openPicker( BuildContext context, { required PickerAdapter adapter, String? title, String? cancelTitle, String? sureTitle, List? selecteds, required PickerConfirmCallback clickCallBack, }) { Picker( adapter: adapter, title: Text( title ?? '请选择'.tr, style: TextStyle( color: titleColor, fontSize: textFontSize, ), ), selecteds: selecteds, confirmText: sureTitle??'确定'.tr, cancelText: cancelTitle??'取消'.tr, cancelTextStyle: TextStyle( color: btnColor, fontSize: textFontSize, ), confirmTextStyle: TextStyle( color: btnColor, fontSize: textFontSize, ), textAlign: TextAlign.right, itemExtent: itemHeight, height: pickerHeight, selectedTextStyle: const TextStyle( color: Colors.black, ), onConfirm: clickCallBack, ).showModal(context); } }