xSch_DateFormField_Builder method
DateTime Editor Generico da Usare
Implementation
Widget xSch_DateFormField_Builder({
required XCol xCol,
required Function(DateTime)? onDateSelected,
bool editable = true,
DateTime? value,
Color? borderColor,
Color? borderColor_Disabled,
Color? labelColor_Disabled,
Function()? onBefore_Edit,
TextEditingController? controller,
String? format,
}) {
OutlineInputBorder o = OutlineInputBorder(
borderSide: BorderSide(
color: widget.xApp != null && widget.xApp!.enterpriseMode
? XColors.enterpriseMode_Foreground
: xCol.readOnly.not()
? (borderColor_Active ? xCol.xmodelXprop.col_Color : borderColor ?? Colors.grey[400]!)
: (borderColor_Disabled ?? Colors.grey[800]!),
width: 1));
return GestureDetector(
child: Container(
margin: EdgeInsets.only(top: 1),
child: xCol.readOnly.not()
? DateTimeFormField(
decoration: InputDecoration(
contentPadding: EdgeInsets.only(right: 2, top: 6, bottom: 6, left: 4),
hintStyle: XStyles.xStyTextForDescr(fontSize: 15, textColor: XSchedaState.color_HintText),
errorStyle: TextStyle(color: Colors.redAccent),
border: o,
disabledBorder: o,
enabledBorder: o,
focusedBorder: o,
labelText: xCol.colCaption,
constraints: BoxConstraints(maxHeight: 48),
labelStyle: value != null
? XStyles.xStyTextForLabel(
textColor: xCol.readOnly
? (labelColor_Disabled ?? borderColor_Disabled ?? Colors.grey[900]!)
: widget.xApp != null && widget.xApp!.enterpriseMode
? XColors.enterpriseMode_Foreground
: (labelColor_Disabled ?? borderColor ?? Colors.grey[600]!)) //
: XStyles.xStyTextForDescr(
textColor: widget.xApp != null && widget.xApp!.enterpriseMode
? XColors.enterpriseMode_Foreground
: editable.not()
? (labelColor_Disabled ?? borderColor_Disabled ?? Colors.grey[700]!)
: (xCol.xmodelXprop.col_Color != Colors.black ? xCol.xmodelXprop.col_Color : XColors.foregroundLight)),
),
onChanged: (value) => onDateSelected!(value!),
onTap: xCol.readOnly.not() ? null : () {},
// enabled: xCol.readOnly.not(),
initialValue: value,
style: XStyles.xStyTextForDescr(fontSize: 15, textColor: widget.xApp != null && widget.xApp!.enterpriseMode ? XColors.enterpriseMode_Foreground : Colors.white),
materialDatePickerOptions: MaterialDatePickerOptions(
initialEntryMode: DatePickerEntryMode.calendar,
initialDatePickerMode: DatePickerMode.day,
),
dateFormat: DateFormat(format ?? "dd/MM/yy"),
mode: DateTimeFieldPickerMode.date,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (e) => (e?.day ?? 0) == 1 ? 'Perfavore sistema la data' : null,
)
: XTextFormField(
controller: value != null ? null : controller,
border: o,
disabledBorder: o,
enabledBorder: o,
focusedBorder: o,
label: xCol.colCaption + (editable ? "🔒" : ""),
onTap: () {
if (controller != null && xCol.dataType != String) controller.selection = TextSelection(baseOffset: 0, extentOffset: controller.text.length);
onBefore_Edit!();
},
initialValue: XUtils.dateToString(value, format: format ?? "dd/MM/yy"),
isCollapsed: false,
enabled: editable.not(),
height: null,
fillColor: editable ? Colors.transparent : XSchedaState.color_CellBackGorundDisabled,
filled: XSchedaState.color_CellBackGorundDisabled != null ? true : false,
suffixIcon: xCol.format == "C" ? Icon(Icons.euro, size: 20) : null,
suffixIconConstraints: BoxConstraints(maxWidth: 20, minWidth: 20, maxHeight: 30, minHeight: 30),
contentPadding: EdgeInsets.only(top: 8, left: 5, bottom: 8),
textStyle: XStyles.xStyTextForDescr(textColor: widget.xApp != null && widget.xApp!.enterpriseMode ? XColors.enterpriseMode_Foreground : labelColor_Disabled ?? XSchedaState.color_Text),
textAlign: TextAlign.start,
labelStyle: XStyles.xStyTextForLabel(textColor: xCol.xmodelXprop.col_Color == Colors.black ? XColors.foregroundLight : xCol.xmodelXprop.col_Color), //XSchedaState.colorOfHintText
hintStyle: XStyles.xStyTextForSubDescr(textColor: XSchedaState.color_HintText),
)));
}