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