skip to Main Content
handleDataSrc(List<dynamic> dataSrc) {
    final List<PlutoRow> rows = dataSrc.map((dynamic item) {
      Map<String, PlutoCell> cells = {};
      for (var key in item.keys) {
        if (item[key] != null) {
          cells[key] = PlutoCell(value: "${item[key]}");
        }
      }
      PlutoRow row = PlutoRow(cells: cells);
      return row;
    }).toList();
    return rows;
  }
 // this way will not work
 // var rows = handleDataSrc(widget.dataSrc);
 var rows = [
                PlutoRow(
                  cells: {
                    'id': PlutoCell(value: "6580910ddc65492c839bf6e9"),
                    'shipmentID': PlutoCell(value: 'xxx'),
                    'companyCode': PlutoCell(value: 'AAR'),
                    'shipmentETD': PlutoCell(value: 'xxxx'),
                    'shipmentETA': PlutoCell(value: 'xxxx'),
                    'createdAt': PlutoCell(value: '2021-01-01'),
                    'updatedAt': PlutoCell(value: 'xxxx'),
                  },
                )
              ];

I handle the data source in code, and I check the variables in side tabs, it’s all ok, but the view will not show the data . don’t know what’s wrong.
if I write the rows literally, it will work! really need help !!! although I think it may be a tiny issue in code, many thanks!!

work:
work

not work with the rows shows below

image

notwork

1. The values have been checked for excluding null value

2. checked the pic above for the keys are totally matched

2

Answers


  1. It seems like you’re trying to convert a list of maps (dataSrc) into a list of PlutoRow objects. The issue might be related to how you’re handling the data conversion.

    One potential issue could be the data types. The PlutoCell constructor expects a String value, but if your item[key] is not a string, it could cause issues. You’re using string interpolation ("${item[key]}") to convert it to a string, but if item[key] is null, it will result in the string "null", which might not be what you want.

    Another potential issue could be with the keys. If the keys in your item maps don’t match the keys you’re using when you manually create the PlutoRow objects, the rows won’t be created correctly.

    Here’s a slightly modified version of your handleDataSrc function that checks for null values and logs any keys that aren’t found in the item maps:

    handleDataSrc(List<dynamic> dataSrc) {
      final List<PlutoRow> rows = dataSrc.map((dynamic item) {
        Map<String, PlutoCell> cells = {};
        for (var key in item.keys) {
          if (item[key] != null) {
            cells[key] = PlutoCell(value: "${item[key]}");
          } else {
            print('Null value for key: $key');
          }
        }
        PlutoRow row = PlutoRow(cells: cells);
        return row;
      }).toList();
      return rows;
    }
    

    Try using this version of the function and check the console for any output. This might give you a clue about what’s going wrong.

    Login or Signup to reply.
  2. When PlutoGrid is initially rendered, the rows are an empty list, and after asynchronously fetching the data, the view is not updated. You can try using a boolean loading state for conditional rendering of PlutoGrid.

    body: Container(
            padding: const EdgeInsets.all(30),
            child: loading ? const Center(child: Text('Loading'),) : PlutoGrid(
                columns: columns,
                rows: rows,
                onChanged: (PlutoGridOnChangedEvent event) {
                  print(event);
                },
                onLoaded: (PlutoGridOnLoadedEvent event) {
                  print(event);
                }
            ),
          ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search