From f5eaef39aca2aad544eaca9224caa6a082b01b40 Mon Sep 17 00:00:00 2001 From: Jorian van der Kolk Date: Mon, 2 Jan 2023 11:02:32 +0100 Subject: [PATCH] fixed skipping month bug --- CHANGELOG.md | 4 +++ lib/src/enums/date_box_shape.dart | 6 +---- lib/src/extensions/date_time.dart | 1 - lib/src/overlay_date_time_picker.dart | 25 ++++++------------- .../week_date_time_picker_sheet.dart | 3 +-- pubspec.yaml | 2 +- 6 files changed, 15 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bed6be..e332c15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.2.3 + +- Fixed skipping month bug + ## 2.2.2 - Made the popup dismissible diff --git a/lib/src/enums/date_box_shape.dart b/lib/src/enums/date_box_shape.dart index 97d291f..79f6eed 100644 --- a/lib/src/enums/date_box_shape.dart +++ b/lib/src/enums/date_box_shape.dart @@ -3,8 +3,4 @@ // SPDX-License-Identifier: BSD-3-Clause /// Defines the shape of a specific date. -enum DateBoxShape { - circle, - rectangle, - roundedRectangle -} \ No newline at end of file +enum DateBoxShape { circle, rectangle, roundedRectangle } diff --git a/lib/src/extensions/date_time.dart b/lib/src/extensions/date_time.dart index e1b40e8..0515038 100644 --- a/lib/src/extensions/date_time.dart +++ b/lib/src/extensions/date_time.dart @@ -31,7 +31,6 @@ extension DateTimeExtension on DateTime { bool get isLeapYear => (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0); - /// Returns the amount of days in the current month of the [DateTime] object int daysInMonth() { return DateTime(year, month + 1, 0).day; diff --git a/lib/src/overlay_date_time_picker.dart b/lib/src/overlay_date_time_picker.dart index 78c302a..e514855 100644 --- a/lib/src/overlay_date_time_picker.dart +++ b/lib/src/overlay_date_time_picker.dart @@ -3,7 +3,6 @@ // SPDX-License-Identifier: BSD-3-Clause import 'package:flutter/material.dart'; -import 'package:flutter_date_time_picker/src/extensions/date_time.dart'; import 'package:flutter_date_time_picker/src/models/date_time_picker_theme.dart'; import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart'; import 'package:flutter_date_time_picker/src/models/date_constraint.dart'; @@ -232,14 +231,10 @@ class _OverlayDateTimePickerState extends State { void nextDate() { if (!mounted) return; setState(() { - _dateTimePickerController.browsingDate = - _dateTimePickerController.browsingDate.add( - Duration( - days: DateTime( - _dateTimePickerController.browsingDate.year, - _dateTimePickerController.browsingDate.month, - ).daysInMonth(), - ), + _dateTimePickerController.browsingDate = DateTime( + _dateTimePickerController.browsingDate.year, + _dateTimePickerController.browsingDate.month + 1, + _dateTimePickerController.browsingDate.day, ); }); } @@ -247,14 +242,10 @@ class _OverlayDateTimePickerState extends State { void previousDate() { if (!mounted) return; setState(() { - _dateTimePickerController.browsingDate = - _dateTimePickerController.browsingDate.subtract( - Duration( - days: DateTime( - _dateTimePickerController.browsingDate.year, - _dateTimePickerController.browsingDate.month, - ).daysInMonth(), - ), + _dateTimePickerController.browsingDate = DateTime( + _dateTimePickerController.browsingDate.year, + _dateTimePickerController.browsingDate.month - 1, + _dateTimePickerController.browsingDate.day, ); }); } diff --git a/lib/src/widgets/week_date_time_picker/week_date_time_picker_sheet.dart b/lib/src/widgets/week_date_time_picker/week_date_time_picker_sheet.dart index d39f93f..0a3f94c 100644 --- a/lib/src/widgets/week_date_time_picker/week_date_time_picker_sheet.dart +++ b/lib/src/widgets/week_date_time_picker/week_date_time_picker_sheet.dart @@ -21,8 +21,7 @@ class WeekDateTimePickerSheet extends StatelessWidget { final double weekDateBoxSize; String _getDateHeader(BuildContext context) { - var weekDays = - dateTimePickerController.browsingDate.daysOfWeek(); + var weekDays = dateTimePickerController.browsingDate.daysOfWeek(); var firstDay = weekDays.first.day.toString(); diff --git a/pubspec.yaml b/pubspec.yaml index d814525..2648ebc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_date_time_picker description: A Flutter package for date and time picker. -version: 2.2.2 +version: 2.2.3 homepage: https://iconica.nl/ environment: