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

[Bug] `startDate` in `PlutoColumnType.date` skips the first date #883

Closed beriaanirudh closed 1 year ago

beriaanirudh commented 1 year ago

Steps to reproduce the bug

PlutoColumn(title: "Due Date", field: DueDateField,
        type: PlutoColumnType.date(format: "dd/MM/yyyy", startDate: DateTime.now())

Expected results

Calendar's first valid date is today.

Actual results

Calendar's first valid date is tomorrow.

Fix

We should compare on year, month and day; and not compare hour, min, ms. Copying from a utility in TableCalendar

/// Checks if two DateTime objects are the same day.
/// Returns `false` if either of them is null.
bool isSameDay(DateTime? a, DateTime? b) {
  if (a == null || b == null) {
    return false;
  }

  return a.year == b.year && a.month == b.month && a.day == b.day;
}

Current possible Workaround:

final now = DateTime.now();
PlutoColumn(title: "Due Date", field: DueDateField,
        type: PlutoColumnType.date(format: "dd/MM/yyyy", startDate: DateTime(now.year, now.month, now.day))

Execution Environment

PlutoGrid version is 7.0.2

PS: Thanks for this awesome library!

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.