bosskmk / pluto_grid

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.

Home Page:https://pluto.weblaze.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LateInitializationError: Field '_column@1169200100' has not been initialized.

jonahzheng opened this issue · comments

The following LateError was thrown during a scheduler callback:
LateInitializationError: Field '_column@1169200100' has not been initialized.

When the exception was thrown, this was the stack: 
#0      PlutoCell._column (package:pluto_grid/src/model/pluto_cell.dart)
#1      PlutoCell.column (package:pluto_grid/src/model/pluto_cell.dart:47:29)
#2      EditingState.changeCellValue (package:pluto_grid/src/manager/state/editing_state.dart:179:32)
#3      TextCellState._changeValue (package:pluto_grid/src/ui/cells/text_cell.dart:138:25)
#4      TextCellState.dispose.<anonymous closure> (package:pluto_grid/src/ui/cells/text_cell.dart:59:9)
#5      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1146:15)
#6      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1091:9)
#7      SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:997:5)
#11     _invoke (dart:ui/hooks.dart:151:10)
#12     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5)
#13     _drawFrame (dart:ui/hooks.dart:115:31)
(elided 3 frames from dart:async)

edit cell

            onChanged: (PlutoGridOnChangedEvent event) {
              log('new: '+ event.value);
              //event.cells[event.column.field]!.value.toString(),
             // print(event);
            },

flutter 3.0

pluto_grid:2.10.0

A PlutoColumn is provided first in the PlutoGrid constructor or must be added with the stateManager.insertColumns method in order for columns to be added at runtime.

Otherwise, the PlutoCell.column value will not be set and an error will occur.

final columns = <PlutoColumn>[
// ...columns
];
PlutoGrid(
  columns: columns,

// or

stateManager.insertColumns(0, [PltuoColumn(), PlutoColumn()]);

If this answer did not solve the problem, I would appreciate it if you could provide a minimal code that can reproduce the error.

Had the same problem, figured it was related to the grid mode. Issue happens when the grid mode is PlutoGridMode.select and PlutoGridMode.selectWithOneTap as well.

@FloRul
Can you provide minimal sample code to reproduce the error?

https://github.com/FloRul/pluto_grid_test/tree/master

[√] Flutter (Channel stable, 3.0.5, on Microsoft Windows [version 10.0.19043.1766], locale fr-CA)
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
X cmdline-tools component is missing
Run path/to/sdkmanager --install "cmdline-tools;latest"
See https://developer.android.com/studio/command-line for more details.
X Android license status unknown.
Run flutter doctor --android-licenses to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[!] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.4)
X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and
include these components:
MSVC v142 - VS 2019 C++ x64/x86 build tools
- If there are multiple build tool versions available, install the latest
C++ CMake tools for Windows
Windows 10 SDK
[√] Android Studio (version 2020.3)
[√] VS Code (version 1.68.1)
[√] Connected device (3 available)
[√] HTTP Host Availability

══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
The following LateError was thrown during a scheduler callback:
LateInitializationError: Field '_column' has not been initialized.
When the exception was thrown, this was the stack:
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49 throw
packages/pluto_grid/src/model/pluto_cell.dart 46:20 get [_column]
packages/pluto_grid/src/model/pluto_cell.dart 44:29 get column
packages/pluto_grid/src/manager/state/column_state.dart 318:41 get currentColumn
packages/pluto_grid/src/manager/state/editing_state.dart 54:56 get autoEditing
packages/pluto_grid/src/manager/state/cell_state.dart 213:16 setCurrentCell
packages/pluto_grid/src/pluto_grid.dart 497:23
packages/flutter/src/scheduler/binding.dart 1146:15 [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1091:9 handleDrawFrame
packages/flutter/src/scheduler/binding.dart 864:7
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19 internalCallback
════════════════════════════════════════════════════════════════════════════════════════════════════

@FloRul

In your code, you are specifying a field in a column that does not exist in Row.

Apart from this issue, It seems that PlutoGrid should display the correct error message for the error.

Thanks for reporting the error.

I will close this issue.

rows: [
  PlutoRow(
    key: UniqueKey(),
    cells: {
      // This field id is not specfic in columns
      'id': PlutoCell(value: 2),
      'quotaNumber': PlutoCell(value: 'quotaNumber'),
      'vendorNumber': PlutoCell(value: 'vendorNumber'),
      'name': PlutoCell(value: 'companyName'),
      'origin': PlutoCell(value: 'origin.code'),
      'cycleType': PlutoCell(value: 'origin'),
      'cycleTolerance': PlutoCell(value: 'cycleTolerance'),
      'henhousesCount': PlutoCell(value: 'henhousesCount'),
      'city': PlutoCell(value: 'city'),
      'phone1': PlutoCell(value: 'phone1'),
      'phone2': PlutoCell(value: 'phone2'),
      'totalCapacity': PlutoCell(value: 'henhousesTotalCapacity'),
      'isActive': PlutoCell(value: 'active'),
    },
  ),
],

Added to the document how to add or remove columns and rows after setting them.

https://pluto.weblaze.dev/add-and-remove-columns-and-rows

@bosskmk thank you for you raplay,
this error is occur, because I use getx with pluto_gird, it doesn't seem to work correctly.
now I use this code to update pluto_grid

      gridStateManager?.removeAllRows();
      gridStateManager?.prependRows(rows);