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);
  }

  if (xCol.dataType == String && xCol.colKey.startsWith("li").not()) {
    _xContainerOfWidgets = Text(
      item[xCol.colKey] != null ? item[xCol.colKey] : ((noTextWhenCellValueIsNull) ? "<No Text>" : ""),
      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),
        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.format == "C") {
      _xContainerOfWidgets = Text(XUtils.xFormatToCurrency(context, item[xCol.colKey] ?? 0.0),
          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);
      // Se è un un semplice double
    } else 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 {
      _xContainerOfWidgets = Text(item[xCol.colKey] != null ? item[xCol.colKey].toString() : "0.0", style: widget.xCells_Item_TextStyle == null ? XStyles.xStyTextForDescr(textColor: xColColor) : widget.xCells_Item_TextStyle!(xCol, item, xColColor));
    }
  }
  //WIDGET NEL CASO FOSSE UN INTERO
  else if (xCol.dataType == int) {
    _xContainerOfWidgets = Text(item[xCol.colKey] != null ? item[xCol.colKey].toString() : "0", style: widget.xCells_Item_TextStyle == null ? XStyles.xStyTextForDescr(textColor: xColColor) : widget.xCells_Item_TextStyle!(xCol, item, xColColor), textAlign: TextAlign.left);

    //Se fosse una lista e voglio prendere la quantità di oggetti dentro
  } else if (xCol.dataType == bool) {
    _xContainerOfWidgets = Container(
      child: XCheckBoxWidget(
          verticalCheckBoxWidget: true,
          label: xCol.colCaption,
          label_Color: xCol.xmodelXprop.col_Color,
          activeColor: xCol.xmodelXprop.col_Color,
          checkColor: XColors.foregroundDark,
          value: (item[xCol.colKey] ?? false),
          onChanged: (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) ? "<No Text>" : "")),
        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 * XUtils.kforScale;
    return xCol.hidden ? Container() : Container(padding: EdgeInsets.symmetric(horizontal: 2), alignment: Alignment.centerLeft, width: flexible ? null : (widget.xCells_Item_Width == null ? wOfCell : (widget.xCells_Item_Width!(xCol, item, wOfCell))), child: _xContainerOfWidgets);
  } else {
    return widget.xCells_Item_Widget!(xCol, item);
  }
}