app-starlock/lib/tools/pickers/style/picker_style.dart

189 lines
4.7 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2024-08-19 15:24:14 +08:00
import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_colors.dart';
/// 基础样式
/// [showTitleBar] 是否显示头部(选择器以上的控件) 默认true
/// [menu] 头部和选择器之间的菜单widget,默认null 不显示
/// [title] 头部 中间的标题 默认SizedBox() 不显示
/// [pickerHeight] 选择器下面 picker 的整体高度 固定高度220.0
/// [pickerTitleHeight] 选择器上面 title 确认、取消的整体高度 固定高度44.0
/// [pickerItemHeight] 选择器每个被选中item的高度40.0
/// [menuHeight] 头部和选择器之间的菜单高度 固定高度36.0
/// [cancelButton] 头部的取消按钮
/// [commitButton] 头部的确认按钮
/// [textColor] 选择器的文字颜色 默认黑色
/// [textSize] 选择器的文字大小
/// [backgroundColor] 选择器的背景颜色 默认白色
/// [headDecoration] 头部Container 的Decoration 默认BoxDecoration(color: Colors.white)
///
class PickerStyle {
BuildContext? _context;
bool? _showTitleBar;
Widget? _menu;
double? _pickerHeight;
double? _pickerTitleHeight;
double? _pickerItemHeight;
double? _menuHeight;
Widget? _cancelButton;
Widget? _commitButton;
Widget? _title;
Decoration? _headDecoration;
Color? _backgroundColor;
Color? _textColor;
double? _textSize;
Widget? _itemOverlay;
PickerStyle({
BuildContext? context,
bool? showTitleBar,
Widget? menu,
double? pickerHeight,
double? pickerTitleHeight,
double? pickerItemHeight,
double? menuHeight,
Widget? cancelButton,
Widget? commitButton,
Widget? title,
Decoration? headDecoration,
Color? backgroundColor,
Color? textColor,
double? textSize,
Widget? itemOverlay,
}) {
2024-08-19 15:24:14 +08:00
_context = context;
_showTitleBar = showTitleBar;
_menu = menu;
2024-08-19 15:24:14 +08:00
_pickerHeight = pickerHeight;
_pickerTitleHeight = pickerTitleHeight;
_pickerItemHeight = pickerItemHeight;
_menuHeight = menuHeight;
2024-08-19 15:24:14 +08:00
_cancelButton = cancelButton;
_commitButton = commitButton;
_title = title;
_headDecoration = headDecoration;
_backgroundColor = backgroundColor;
_textColor = textColor;
_textSize = textSize;
_itemOverlay = itemOverlay;
}
set context(BuildContext? value) {
_context = value;
}
set menuHeight(double value) {
_menuHeight = value;
}
set menu(Widget? value) {
_menu = value;
}
set pickerHeight(double value) {
_pickerHeight = value;
}
set pickerTitleHeight(double value) {
_pickerTitleHeight = value;
}
set pickerItemHeight(double value) {
_pickerItemHeight = value;
}
set cancelButton(Widget value) {
_cancelButton = value;
}
set commitButton(Widget value) {
_commitButton = value;
}
set itemOverlay(Widget? value) {
_itemOverlay = value;
}
set title(Widget value) {
_title = value;
}
set headDecoration(Decoration value) {
_headDecoration = value;
}
set backgroundColor(Color value) {
_backgroundColor = value;
}
set textColor(Color value) {
_textColor = value;
}
set textSize(double? value) {
_textSize = value;
}
set showTitleBar(bool value) {
_showTitleBar = value;
}
2024-08-19 15:24:14 +08:00
BuildContext? get context => _context;
/// 选择器背景色 默认白色
2024-08-19 15:24:14 +08:00
Color get backgroundColor => _backgroundColor ?? Colors.white;
Decoration get headDecoration =>
2024-08-19 15:24:14 +08:00
_headDecoration ?? const BoxDecoration(color: Colors.white);
2024-08-19 15:24:14 +08:00
Widget? get menu => _menu;
2024-08-19 15:24:14 +08:00
double get menuHeight => _menuHeight ?? 36.0;
2024-08-19 15:24:14 +08:00
double get pickerHeight => _pickerHeight ?? 220.0;
2024-08-19 15:24:14 +08:00
double get pickerItemHeight => _pickerItemHeight ?? 40.0;
2024-08-19 15:24:14 +08:00
double get pickerTitleHeight => _pickerTitleHeight ?? 44.0;
2024-08-19 15:24:14 +08:00
bool get showTitleBar => _showTitleBar ?? true;
2024-08-19 15:24:14 +08:00
Color get textColor => _textColor ?? Colors.black87;
2024-08-19 15:24:14 +08:00
double? get textSize => _textSize;
2024-08-19 15:24:14 +08:00
Widget get title => _title ?? const SizedBox();
Widget get commitButton => getCommitButton();
Widget get cancelButton => getCancelButton();
2024-08-19 15:24:14 +08:00
Widget? get itemOverlay => _itemOverlay;
Widget getCommitButton() {
2024-08-19 15:24:14 +08:00
return _commitButton ??
Container(
alignment: Alignment.center,
padding: const EdgeInsets.only(left: 12, right: 22),
2024-08-19 15:24:14 +08:00
child: Text('确定'.tr,
style: TextStyle(color: AppColors.mainColor, fontSize: 16.0)),
);
}
Widget getCancelButton() {
2024-08-19 15:24:14 +08:00
return _cancelButton ??
Container(
alignment: Alignment.center,
padding: const EdgeInsets.only(left: 22, right: 12),
2024-08-19 15:24:14 +08:00
child: Text('取消'.tr,
style: TextStyle(
color: Theme.of(context!).unselectedWidgetColor,
fontSize: 16.0)),
);
}
}