doonfrs / pluto_grid_plus

PlutoGrid is a dataGrid for flutter that can be controlled by the keyboard on desktop and web. Of course, it works well on Android and IOS.
https://pluto.weblaze.dev
MIT License
27 stars 28 forks source link

[Bug] Null exception on missing field #2

Closed michaelbushe closed 9 months ago

michaelbushe commented 10 months ago

This errors on an unchecked null check. Added null check and warning in debug to help developers know what row and column have the issue.

Steps to reproduce the bug

Initialize a grid with a cell that refers to a field that doesn't exist in the columns.

Expected results

Nothing, in debug, print a helpful warning.

Actual results

UI blows up on "Unexpected null value."

Code sample

      final List<PlutoColumn> columns = [
        PlutoColumn(
            title: 'Here',
            field: 'here',
            width: 50,
            type: PlutoColumnType.text(defaultValue: 'foo'))
      ];

      final List<PlutoRow> rows = [
        PlutoRow(cells: {'here': PlutoCell(value: 'here')}),
        PlutoRow(cells: {'there': PlutoCell(value: 'there')}),
      ];

      PlutoGridStateManager.initializeRows(
        columns,
        rows,
        forceApplySortIdx: true,
      );

Execution Environment

3.16.8

PlutoGridPlus version PlutoGridPlus version is 8.2.0

OS Mac Sonoma

michaelbushe commented 10 months ago

I have a fix but my push is getting denied, thank you in advance.

doonfrs commented 9 months ago

Hi @michaelbushe I don't know if it is correct to create a row with a non-existent column, this will break the sorting, the counting, etc ... all functions may trigger unexpected exceptions. You can use it in your fork as it is working with you, but I don't feel it is safe to merge this PR in the main repo.

best;