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.
https://pluto.weblaze.dev
MIT License
664 stars 305 forks source link

Problem with displaying date type columns after upgrading flutter, pluto_grid and intl packages[Help] #906

Closed jozes closed 1 year ago

jozes commented 1 year ago

Hi! I have recently upgraded flutter from version 3.3.10 to 3.10.6 (latest stable version), and pluto_grid from 5.3.2 to 7.0.2 (latest). The initl package was upgraded from 0.17 to 0.18. as well. Now my reports are crashing when I try to display date type column in non default date format 'dd.MM.yyyy'. There was no change in code of the report. Actually I have many reports of this kind and all would need a fix for this problem.

Here is the code that was working until upgrade:

in column definition: PlutoColumn( title: 'Nabran', field: 'datum_nabirka', type: PlutoColumnType.date(format: 'dd.MM.yyyy'), width: 100, ), in Future<List> fetchRows() async {

_rows.add(PlutoRow( cells: { ..... 'datum_nabirka': PlutoCell(value: v['datum_nabirka']), .... })); }

The "v['datum_nabirka']" is of format "2023-06-22". or "2023-06-22 00:00:00.000".

The report crashes with the following exception: Exception has occurred. "Error: FormatException: Trying to read . from 2023-06-22 at 5 dart-sdk/lib/_internal/js_dev_runtime/private/ddcruntime/errors.dart 288:49 throw packages/intl/src/intl/date_format_field.dart 87:5 throwFormatException packages/intl/src/intl/date_format_field.dart 56:7 parseLiteral packages/intl/src/intl/date_format_field.dart 100:5 parse packages/intl/src/intl/date_format.dart 384:12 [_parse] packages/intl/src/intl/date_format.dart 315:7 parse packages/pluto_grid/src/model/pluto_column_type.dart 460:36 makeCompareValue packages/pluto_grid/src/model/pluto_cell.dart 90:12 [_getValueForSorting] packages/pluto_grid/src/model/pluto_cell.dart 73:24 setColumn packages/pluto_grid/src/manager/pluto_grid_state_manager.dart 558:11 packages/pluto_grid/src/manager/pluto_grid_state_manager.dart 559:21 execute packages/pluto_grid/src/manager/pluto_grid_state_manager.dart 537:13 execute packages/pluto_grid/src/manager/pluto_grid_state_manager.dart 289:16 initializeRows

Second option: storing string in format 'dd.MM.yyyy' 'datum_nabirka': PlutoCell(value: DateFormat('dd.MM.yyyy', "si_SL") .format( DateTime.tryParse(v['datum_nabirka'].toString())!),

In this case I get the following exception: Exception has occurred. "Error: FormatException: Invalid date format 15.06.2023 dart-sdk/lib/_internal/js_dev_runtime/private/ddcruntime/errors.dart 288:49 throw dart-sdk/lib/core/date_time.dart 355:7 parse dart-sdk/lib/core/date_time.dart 366:14 tryParse packages/pluto_grid/src/model/pluto_column_type.dart 470:33 applyFormat packages/pluto_grid/src/model/pluto_column_type.dart 231:54 PlutoColumnTypeExtension.applyFormat packages/pluto_grid/src/model/pluto_cell.dart 94:28 [_applyFormatOnInit] packages/pluto_grid/src/model/pluto_cell.dart 49:7 get value packages/pluto_grid/src/ui/cells/pluto_default_cell.dart 110:58 updateState packages/pluto_grid/src/ui/cells/pluto_default_cell.dart 88:5 initState packages/flutter/src/widgets/framework.dart 5219:55 [_firstBuild] packages/flutter/src/widgets/framework.dart 5062:5 mount packages/flutter/src/widgets/framework.dart 3971:15 inflateWidget

Third option: It doesn't help if store a date data type in PlutoCell like:

'datum_nabirka': PlutoCell( value: DateTime.tryParse(v['datum_nabirka'].toString())!),

Then the exception is: Exception has occurred. "Error: FormatException: Trying to read . from 2023-06-22 00:00:00.000 at 5 dart-sdk/lib/_internal/js_dev_runtime/private/ddcruntime/errors.dart 288:49 throw packages/intl/src/intl/date_format_field.dart 87:5 throwFormatException packages/intl/src/intl/date_format_field.dart 56:7 parseLiteral packages/intl/src/intl/date_format_field.dart 100:5 parse packages/intl/src/intl/date_format.dart 384:12 [_parse] packages/intl/src/intl/date_format.dart 315:7 parse packages/pluto_grid/src/model/pluto_column_type.dart 460:36 makeCompareValue packages/pluto_grid/src/model/pluto_cell.dart 90:12 [_getValueForSorting] packages/pluto_grid/src/model/pluto_cell.dart 73:24 setColumn packages/pluto_grid/src/manager/pluto_grid_state_manager.dart 558:11 packages/pluto_grid/src/manager/pluto_grid_state_manager.dart 559:21 execute packages/pluto_grid/src/manager/pluto_grid_state_manager.dart 537:13 execute packages/pluto_grid/src/manager/pluto_grid_state_manager.dart 289:16 initializeRows packages/pluto_grid/src/manager/pluto_grid_state_manager.dart 359:38

In all cases the v['datum_nabirka'] has the same format as stated above.

The workaround is to define a text type PlutoColumn, however the sort on this column is wrong as it sorts not as a date but as a string. Sorting was perfectly working before upgrade.

Any suggestions would be very helpful. Thanks in advance for your answer.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 year ago

This issue was closed because it has been inactive for 14 days since being marked as stale.