189 lines
4.7 KiB
Dart
Executable File
189 lines
4.7 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
||
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,
|
||
}) {
|
||
_context = context;
|
||
_showTitleBar = showTitleBar;
|
||
_menu = menu;
|
||
|
||
_pickerHeight = pickerHeight;
|
||
_pickerTitleHeight = pickerTitleHeight;
|
||
_pickerItemHeight = pickerItemHeight;
|
||
_menuHeight = menuHeight;
|
||
|
||
_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;
|
||
}
|
||
|
||
BuildContext? get context => _context;
|
||
|
||
/// 选择器背景色 默认白色
|
||
Color get backgroundColor => _backgroundColor ?? Colors.white;
|
||
|
||
Decoration get headDecoration =>
|
||
_headDecoration ?? const BoxDecoration(color: Colors.white);
|
||
|
||
Widget? get menu => _menu;
|
||
|
||
double get menuHeight => _menuHeight ?? 36.0;
|
||
|
||
double get pickerHeight => _pickerHeight ?? 220.0;
|
||
|
||
double get pickerItemHeight => _pickerItemHeight ?? 40.0;
|
||
|
||
double get pickerTitleHeight => _pickerTitleHeight ?? 44.0;
|
||
|
||
bool get showTitleBar => _showTitleBar ?? true;
|
||
|
||
Color get textColor => _textColor ?? Colors.black87;
|
||
|
||
double? get textSize => _textSize;
|
||
|
||
Widget get title => _title ?? const SizedBox();
|
||
|
||
Widget get commitButton => getCommitButton();
|
||
|
||
Widget get cancelButton => getCancelButton();
|
||
|
||
Widget? get itemOverlay => _itemOverlay;
|
||
|
||
Widget getCommitButton() {
|
||
return _commitButton ??
|
||
Container(
|
||
alignment: Alignment.center,
|
||
padding: const EdgeInsets.only(left: 12, right: 22),
|
||
child: Text('确定'.tr,
|
||
style: TextStyle(color: AppColors.mainColor, fontSize: 16.0)),
|
||
);
|
||
}
|
||
|
||
Widget getCancelButton() {
|
||
return _cancelButton ??
|
||
Container(
|
||
alignment: Alignment.center,
|
||
padding: const EdgeInsets.only(left: 22, right: 12),
|
||
child: Text('取消'.tr,
|
||
style: TextStyle(
|
||
color: Theme.of(context!).unselectedWidgetColor,
|
||
fontSize: 16.0)),
|
||
);
|
||
}
|
||
}
|