xLayout_CellWidget_Editable method
Container
xLayout_CellWidget_Editable(
- XCol xCol,
- dynamic item,
- BuildContext context,
- dynamic itemToSet, {
- bool onBeforeCMD_Active = true,
- TextEditingController? controller,
BUILDER DEI WIDGET EDITABILI///
Implementation
Container xLayout_CellWidget_Editable(XCol xCol, dynamic item, BuildContext context, dynamic itemToSet, {bool onBeforeCMD_Active = true, TextEditingController? controller}) {
late Widget _widgetForCell;
//WIDGET NEL CASO FOSSE UNA STRING
if (xCol.dataType == String && xCol.colKey.startsWith("li").not() && xCol.dataType != bool) {
_widgetForCell = FocusScope(
onKeyEvent: (node, event) {
if (event is KeyDownEvent && event.logicalKey.keyLabel == LogicalKeyboardKey.escape.keyLabel) {
FocusScope.of(context).unfocus();
return KeyEventResult.handled; // Indica che l'evento è stato gestito
} else if (event is KeyDownEvent && event.logicalKey.keyLabel == LogicalKeyboardKey.tab.keyLabel) {
FocusScope.of(context).nextFocus();
return KeyEventResult.handled; // Indica che l'evento è stato gestito
} else {
return KeyEventResult.skipRemainingHandlers; // Indica che l'evento non è stato gestito
}
},
child: xSch_TextFormField_Builder(
height: null,
context: context,
controller: controller,
xCol: xCol,
multiLines: xCol.width >= 200 ? true : false,
editable: xCol.readOnly,
borderColor: widget.xCell_borderColor,
borderColor_Disabled: widget.xCell_borderColor_Disabled,
labelColor_Disabled: widget.xCell_labelColor_Disabled,
onSubmitted: (value) => xOnXCell_Edit_SubmitValue_INTERNAL(item, xCol, value),
value: item[xCol.colKey] ?? "",
onChanged: (value) => xCells_EditAlert_Active ? xOnXCell_Edit_OnChanged(item, xCol, value) : xOnXCell_Edit_SubmitValue_INTERNAL(item, xCol, value),
onBefore_Edit: xCells_EditAlert_Active
? () {
if (onBeforeCMD_Active) xOnXCell_Before_Edit(xCol, item[xCol.colKey], itemToSet: itemToSet);
}
: null,
));
}
//WIDGET NEL CASO FOSSE UN DATETIME
else if (xCol.dataType == DateTime) {
_widgetForCell = xSch_DateFormField_Builder(
xCol: xCol,
borderColor: widget.xCell_borderColor,
borderColor_Disabled: widget.xCell_borderColor_Disabled,
labelColor_Disabled: widget.xCell_labelColor_Disabled,
format: xFormat_Date,
onBefore_Edit: () => xOnXCell_Before_Edit(xCol, item),
value: item[xCol.colKey] == DateTime(1900, 01, 01) ? null : item[xCol.colKey],
onDateSelected: (value) {
xOnXCell_Edit_SubmitValue_INTERNAL(item, xCol, value);
});
}
//WIDGET NEL CASO FOSSE UN DOUBLE
else if (xCol.dataType == double) {
if (xCol.colKey.startsWith("avanz")) {
if (xCol.readOnly) {
_widgetForCell = Stack(alignment: Alignment.center, children: [
LinearProgressIndicator(
value: (item[xCol.colKey] / 100) ?? 0.0,
minHeight: 20.0,
backgroundColor: Colors.grey[300],
valueColor: AlwaysStoppedAnimation<Color>(xCol.xmodelXprop.col_Color),
),
Text('${item[xCol.colKey]}%', style: XStyles.xStyTextForLabel(textColor: Colors.black, activeBold: true)),
]);
} else {
_widgetForCell = StatefulBuilder(builder: (context, setState) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(children: [
Expanded(
child: Text(
xCol.colCaption,
style: XStyles.xStyTextForLabel(textColor: xCol.xmodelXprop.col_Color == Colors.black ? XColors.foregroundLight : xCol.xmodelXprop.col_Color),
))
]),
SfLinearGauge(
animateAxis: false,
showTicks: false,
showLabels: false,
axisTrackStyle: LinearAxisTrackStyle(thickness: 40, color: Colors.grey[700]),
orientation: LinearGaugeOrientation.horizontal, //
barPointers: [
LinearBarPointer(
value: item[xCol.colKey],
color: xCol.xmodelXprop.col_Color,
thickness: 40,
animationDuration: 0,
)
],
useRangeColorForAxis: true,
markerPointers: <LinearMarkerPointer>[
LinearWidgetPointer(
value: item[xCol.colKey],
enableAnimation: false,
onChangeEnd: (value) {
editedPage.value = true;
xOnXCell_Edit_SubmitValue_INTERNAL(item, xCol, item[xCol.colKey]);
},
onChanged: (dynamic value) => setState(() => item[xCol.colKey] = (value as double).roundToDouble()),
child: Container(
width: 34,
height: 34,
decoration: BoxDecoration(color: Colors.grey[900], boxShadow: <BoxShadow>[BoxShadow(color: Colors.black54, offset: Offset(0.0, 1.0), blurRadius: 6.0)], shape: BoxShape.circle),
child: Center(
child: FittedBox(
child: Text(item[xCol.colKey].toStringAsFixed(0) + "",
style: XStyles.xStyTextForLabel(
textColor: xCol.xmodelXprop.col_Color,
activeBold: true,
))))))
])
],
);
});
}
} else {
_widgetForCell = FocusScope(
onKeyEvent: (node, event) {
if (event is KeyDownEvent && event.logicalKey.keyLabel == LogicalKeyboardKey.escape.keyLabel) {
FocusScope.of(context).unfocus();
return KeyEventResult.handled; // Indica che l'evento è stato gestito
} else if (event is KeyDownEvent && event.logicalKey.keyLabel == LogicalKeyboardKey.tab.keyLabel) {
FocusScope.of(context).nextFocus();
return KeyEventResult.handled; // Indica che l'evento è stato gestito
} else {
return KeyEventResult.skipRemainingHandlers; // Indica che l'evento non è stato gestito
}
},
child: xSch_TextFormField_Builder(
context: context,
selectText: true,
editable: xCol.readOnly,
xCol: xCol,
controller: controller,
maxLines: 1,
borderColor: widget.xCell_borderColor,
borderColor_Disabled: widget.xCell_borderColor_Disabled,
labelColor_Disabled: widget.xCell_labelColor_Disabled,
onBefore_Edit: xCells_EditAlert_Active
? () {
if (onBeforeCMD_Active) xOnXCell_Before_Edit(xCol, item, itemToSet: itemToSet);
}
: null,
keyboardType: TextInputType.number,
value: (item[xCol.colKey] == null || item[xCol.colKey].toString() == "0.0") ? "" : XUtils.xFormatDouble(context, item[xCol.colKey]),
inputFormatters: [FilteringTextInputFormatter.deny(RegExp("[- /,\\\\]"))],
onSubmitted: (value) => xOnXCell_Edit_SubmitValue_INTERNAL(item, xCol, double.parse(value)),
onChanged: (value) {
if (value != "")
xCells_EditAlert_Active.not() ? xOnXCell_Edit_SubmitValue_INTERNAL(item, xCol, double.parse(value)) : xOnXCell_Edit_OnChanged(item, xCol, double.parse(value));
else
xCells_EditAlert_Active.not() ? xOnXCell_Edit_SubmitValue_INTERNAL(item, xCol, 0.0) : xOnXCell_Edit_OnChanged(item, xCol, 0.0);
}));
}
}
//WIDGET NEL CASO FOSSE UN INTERO
else if (xCol.dataType == int) {
_widgetForCell = FocusScope(
onKeyEvent: (node, event) {
if (event is KeyDownEvent && event.logicalKey.keyLabel == LogicalKeyboardKey.escape.keyLabel) {
FocusScope.of(context).unfocus();
return KeyEventResult.handled; // Indica che l'evento è stato gestito
} else if (event is KeyDownEvent && event.logicalKey.keyLabel == LogicalKeyboardKey.tab.keyLabel) {
FocusScope.of(context).nextFocus();
return KeyEventResult.handled; // Indica che l'evento è stato gestito
} else {
return KeyEventResult.skipRemainingHandlers; // Indica che l'evento non è stato gestito
}
},
child: xSch_TextFormField_Builder(
context: context,
editable: xCol.readOnly,
selectText: true,
maxLines: 1,
controller: controller,
xCol: xCol,
borderColor: widget.xCell_borderColor,
borderColor_Disabled: widget.xCell_borderColor_Disabled,
labelColor_Disabled: widget.xCell_labelColor_Disabled,
keyboardType: TextInputType.number,
onBefore_Edit: xCells_EditAlert_Active
? () {
if (onBeforeCMD_Active) xOnXCell_Before_Edit(xCol, item, itemToSet: itemToSet);
}
: null,
onSubmitted: (value) => xOnXCell_Edit_SubmitValue_INTERNAL(item, xCol, value),
value: (item[xCol.colKey] == null || item[xCol.colKey].toString() == "0") ? "" : item[xCol.colKey].toString(),
inputFormatters: [FilteringTextInputFormatter.deny(RegExp("[- /,\\\\]"))],
onChanged: (value) {
if (value != "")
xCells_EditAlert_Active.not() ? xOnXCell_Edit_SubmitValue_INTERNAL(item, xCol, int.parse(value)) : xOnXCell_Edit_OnChanged(item, xCol, int.parse(value));
else
xCells_EditAlert_Active.not() ? xOnXCell_Edit_SubmitValue_INTERNAL(item, xCol, 0) : xOnXCell_Edit_OnChanged(item, xCol, 0);
},
));
} else if (xCol.dataType == bool) {
_widgetForCell = Container(
child: XCheckBoxWidget(
verticalCheckBoxWidget: true,
label: xCol.colCaption,
label_Color: xCol.xmodelXprop.col_Color != Colors.black
? xCol.xmodelXprop.col_Color
: ThemeData.estimateBrightnessForColor(widget.backGroundColor!) == Brightness.light
? XColors.foregroundDark
: XColors.foregroundLight,
activeColor: xCol.xmodelXprop.col_Color != Colors.black
? xCol.xmodelXprop.col_Color
: ThemeData.estimateBrightnessForColor(widget.backGroundColor!) == Brightness.light
? XColors.foregroundDark
: XColors.foregroundLight,
checkColor: XColors.foregroundDark,
value: (item[xCol.colKey] ?? false),
onTap: () {
setState(() {
xOnXCell_Edit_SubmitValue_INTERNAL(item, xCol, (item[xCol.colKey] ?? false).not());
});
},
onChanged: (value) async => setState(() {
xOnXCell_Edit_SubmitValue_INTERNAL(item, xCol, value);
}),
));
} else {
//DEVE essere W e H = 0 se no il Wrap fa casino nel gestirlo e va a "un po' a capo" dopo l'ultimo Widget
return Container(width: 0, height: 0);
}
return Container(
width: xCol.width *
(kIsWeb
? (widget.xApp != null ? (widget.xApp!.KforScale + 0.6) : 1)
: widget.xApp != null
? widget.xApp!.KforScale
: 1),
padding: xCol.dataType == DateTime ? EdgeInsets.only(top: 1 * (XUtils.kforScale)) : null,
child: _widgetForCell,
);
}