xLayout_Item_RowWidgets method

Widget xLayout_Item_RowWidgets(
  1. XCol xCol,
  2. XFDataItem item, {
  3. bool noTextWhenCellValueIsNull = true,
  4. String formatDate = "dd/MM/yy",
  5. bool flexible = false,
})

Override per cambiare il Widget di ogni singola Cella dell'Items

Implementation

Widget xLayout_Item_RowWidgets(XCol xCol, XFDataItem item, {bool noTextWhenCellValueIsNull = true, String formatDate = "dd/MM/yy", bool flexible = false}) {
  Widget _xContainerOfWidgets;
  Color xColColor = xCol.xmodelXprop.col_Color == Colors.black ? XColors.foregroundLight : xCol.xmodelXprop.col_Color;
  if (xCol.resizeStyle == 0 && (item[xCol.colKey] == null || item[xCol.colKey].toString().length == 0)) {
    // se sono FLEX e il mio value è NULL, torno Container()
    return Container(
      height: 0,
      width: 0, //DD FIX il Wrap scazza se il Container ha dim NULL !
    );
  }

  if (xCol.dataType == String && xCol.colKey.startsWith("li").not()) {
    _xContainerOfWidgets = Text(
      item[xCol.colKey] != null ? item[xCol.colKey] : ((noTextWhenCellValueIsNull) ? "" : ""),
      maxLines: xCol.multilines
          ? item[xCol.colKey] == ""
              ? 1
              : 3
          : 1,
      style: widget.xCells_Item_TextStyle == null
          ? (item[xCol.colKey] as String).characters.length > 24
              ? XStyles.xStyTextForDescr(textColor: xColColor, fontSize: 15)
              : XStyles.xStyTextForDescr(textColor: xColColor)
          : widget.xCells_Item_TextStyle!(xCol, item, xColColor),
      textAlign: TextAlign.left,
    );
  }
  //WIDGET NEL CASO FOSSE UN DATETIME
  else if (xCol.dataType == DateTime) {
    _xContainerOfWidgets = Text(
      XUtils.dateToString(item[xCol.colKey] ?? DateTime(1900, 01, 01), format: xCol.format != "" ? xCol.format : formatDate, noDateLabel: ""),
      maxLines: 1,
      style: widget.xCells_Item_TextStyle == null ? XStyles.xStyTextForDescr(textColor: xColColor) : widget.xCells_Item_TextStyle!(xCol, item, xColColor),
      textAlign: TextAlign.left,
    );
  }
  //WIDGET NEL CASO FOSSE UN DOUBLE
  else if (xCol.dataType == double) {
    if (xCol.colKey.startsWith("avanz")) {
      if (xCol.readOnly) {
        _xContainerOfWidgets = Stack(alignment: Alignment.center, children: [
          LinearProgressIndicator(
            value: (item[xCol.colKey] / 100) ?? 0.0,
            minHeight: 20.0,
            backgroundColor: Colors.grey[300],
            valueColor: AlwaysStoppedAnimation<Color>(xColColor),
          ),
          Text('${(item[xCol.colKey] as double).roundToDouble()}%', style: XStyles.xStyTextForDescr(textColor: Colors.black, activeBold: true)),
        ]);
      } else {
        _xContainerOfWidgets = StatefulBuilder(builder: (context, setState) {
          return SfLinearGauge(
              animateAxis: false,
              showTicks: false,
              showLabels: false,
              axisTrackStyle: LinearAxisTrackStyle(thickness: 30, color: Colors.grey[700]),
              orientation: LinearGaugeOrientation.horizontal, //
              barPointers: [LinearBarPointer(value: item[xCol.colKey], color: xColColor, thickness: 30, animationDuration: 0)],
              useRangeColorForAxis: true,
              markerPointers: <LinearMarkerPointer>[
                LinearWidgetPointer(
                    value: item[xCol.colKey],
                    enableAnimation: false,
                    onChangeEnd: (value) async {
                      setState(() {
                        if (item is K)
                          widget.rootItemEdited != null ? widget.rootItemEdited!(item) : null;
                        else
                          widget.itemEdited != null ? widget.itemEdited!(item) : null;
                        if (widget.edited != null) widget.edited!.value = true;

                        item[xCol.colKey] = value.roundToDouble();
                      });
                      if (liEditedItems.any((element) => element.id == item.id).not()) {
                        liEditedItems.add(item as K);
                      }
                      await xOnSave(list);
                    },
                    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: widget.xCells_Item_TextStyle == null
                              ? XStyles.xStyTextForDescr(textColor: xColColor, activeBold: true) //
                              : widget.xCells_Item_TextStyle!(xCol, item, xColColor),
                        )))))
              ]);
        });
      }
    } else {
      if (xCol.format.isNotEmpty)
        _xContainerOfWidgets = Text(
          xCol.format == "C" ? XUtils.xFormatToCurrency(context, item[xCol.colKey] ?? 0.0) : XUtils.xFormatDouble(context, item[xCol.colKey], format: xCol.format),
          style: widget.xCells_Item_TextStyle == null ? XStyles.xStyTextForDescr(textColor: item[xCol.colKey] == 0.0 ? Colors.grey[600]! : xColColor) : widget.xCells_Item_TextStyle!(xCol, item, item[xCol.colKey] == 0.0 ? Colors.grey[600]! : xColColor),
          textAlign: TextAlign.end,
        );
      else
        // Se è un un semplice double
        _xContainerOfWidgets = Text(
          item[xCol.colKey] != null ? item[xCol.colKey].toString() : "",
          style: widget.xCells_Item_TextStyle == null ? XStyles.xStyTextForDescr(textColor: xColColor) : widget.xCells_Item_TextStyle!(xCol, item, xColColor),
          textAlign: TextAlign.end,
        );
    }
  }
  //WIDGET NEL CASO FOSSE UN INTERO
  else if (xCol.dataType == int) {
    _xContainerOfWidgets = Text(
        item[xCol.colKey] != null
            ? xCol.format != ""
                ? XUtils.xFormatInt(context, item[xCol.colKey], format: xCol.format)
                : item[xCol.colKey] != 0
                    ? item[xCol.colKey].toString()
                    : ""
            : "",
        style: widget.xCells_Item_TextStyle == null ? XStyles.xStyTextForDescr(textColor: xColColor) : widget.xCells_Item_TextStyle!(xCol, item, xColColor),
        textAlign: TextAlign.end);

    //Se fosse una lista e voglio prendere la quantità di oggetti dentro
  } else if (xCol.dataType == bool) {
    _xContainerOfWidgets = Container(
      child: XCheckBoxWidget(
          verticalCheckBoxWidget: true,
          label: item[xCol.colKey] ? xCol.colCaption : "",
          label_Color: xCol.xmodelXprop.col_Color,
          activeColor: xCol.xmodelXprop.col_Color,
          checkColor: XColors.foregroundDark,
          isVisible_CheckBox: false,
          value: (item[xCol.colKey] ?? false),
          onTap: xCol.readOnly
              ? null
              : () async {
                  setState(() {
                    if (item is K)
                      widget.rootItemEdited != null ? widget.rootItemEdited!(item) : null;
                    else
                      widget.itemEdited != null ? widget.itemEdited!(item) : null;
                    if (widget.edited != null) widget.edited!.value = true;
                    item[xCol.colKey] = item[xCol.colKey].not();
                  });
                  if (liEditedItems.any((element) => element.id == item.id).not()) {
                    liEditedItems.add(item as K);
                  }
                  await xOnSave(list);
                },
          onChanged: xCol.readOnly
              ? null
              : (value) async {
                  setState(() {
                    if (item is K)
                      widget.rootItemEdited != null ? widget.rootItemEdited!(item) : null;
                    else
                      widget.itemEdited != null ? widget.itemEdited!(item) : null;
                    if (widget.edited != null) widget.edited!.value = true;
                    item[xCol.colKey] = value;
                  });
                  if (liEditedItems.any((element) => element.id == item.id).not()) {
                    liEditedItems.add(item as K);
                  }
                  await xOnSave(list);
                }),
    );
  } else if (xCol.dataType == String && (xCol.colKey.startsWith("li"))) {
    _xContainerOfWidgets = Container();
  } else {
    _xContainerOfWidgets = Text(xCol.headerToolTip + (item[xCol.colKey] != null ? item[xCol.colKey] : ((noTextWhenCellValueIsNull) ? "" : "")),
        style: widget.xCells_Item_TextStyle == null
            ? //
            XStyles.xStyTextForDescr(textColor: xColColor)
            : widget.xCells_Item_TextStyle!(xCol, item, xColColor),
        textAlign: TextAlign.left);
  }
  if (widget.xCells_Item_Widget == null) {
    var wOfCell = xCol.width * (widget.xApp!.KforScale + (kIsWeb ? 0.6 : 0));
    return xCol.hidden
        ? Container()
        : Container(
            padding: EdgeInsets.symmetric(horizontal: 2),
            constraints: widget.xCells_Item_Width == null ? BoxConstraints(minWidth: wOfCell, maxWidth: wOfCell) : null,
            width: widget.xCells_Item_Width != null ? (widget.xCells_Item_Width!(xCol, item, wOfCell)) : null,
            child: _xContainerOfWidgets,
          );
  } else {
    return widget.xCells_Item_Widget!(xCol, item);
  }
}