fixed skipping month bug

This commit is contained in:
Jorian van der Kolk 2023-01-02 11:02:32 +01:00
parent fb92171ff3
commit f5eaef39ac
6 changed files with 15 additions and 26 deletions

View file

@ -1,3 +1,7 @@
## 2.2.3
- Fixed skipping month bug
## 2.2.2 ## 2.2.2
- Made the popup dismissible - Made the popup dismissible

View file

@ -3,8 +3,4 @@
// SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: BSD-3-Clause
/// Defines the shape of a specific date. /// Defines the shape of a specific date.
enum DateBoxShape { enum DateBoxShape { circle, rectangle, roundedRectangle }
circle,
rectangle,
roundedRectangle
}

View file

@ -31,7 +31,6 @@ extension DateTimeExtension on DateTime {
bool get isLeapYear => bool get isLeapYear =>
(year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0); (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0);
/// Returns the amount of days in the current month of the [DateTime] object /// Returns the amount of days in the current month of the [DateTime] object
int daysInMonth() { int daysInMonth() {
return DateTime(year, month + 1, 0).day; return DateTime(year, month + 1, 0).day;

View file

@ -3,7 +3,6 @@
// SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: BSD-3-Clause
import 'package:flutter/material.dart'; 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/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/utils/date_time_picker_controller.dart';
import 'package:flutter_date_time_picker/src/models/date_constraint.dart'; import 'package:flutter_date_time_picker/src/models/date_constraint.dart';
@ -232,14 +231,10 @@ class _OverlayDateTimePickerState extends State<OverlayDateTimePicker> {
void nextDate() { void nextDate() {
if (!mounted) return; if (!mounted) return;
setState(() { setState(() {
_dateTimePickerController.browsingDate = _dateTimePickerController.browsingDate = DateTime(
_dateTimePickerController.browsingDate.add( _dateTimePickerController.browsingDate.year,
Duration( _dateTimePickerController.browsingDate.month + 1,
days: DateTime( _dateTimePickerController.browsingDate.day,
_dateTimePickerController.browsingDate.year,
_dateTimePickerController.browsingDate.month,
).daysInMonth(),
),
); );
}); });
} }
@ -247,14 +242,10 @@ class _OverlayDateTimePickerState extends State<OverlayDateTimePicker> {
void previousDate() { void previousDate() {
if (!mounted) return; if (!mounted) return;
setState(() { setState(() {
_dateTimePickerController.browsingDate = _dateTimePickerController.browsingDate = DateTime(
_dateTimePickerController.browsingDate.subtract( _dateTimePickerController.browsingDate.year,
Duration( _dateTimePickerController.browsingDate.month - 1,
days: DateTime( _dateTimePickerController.browsingDate.day,
_dateTimePickerController.browsingDate.year,
_dateTimePickerController.browsingDate.month,
).daysInMonth(),
),
); );
}); });
} }

View file

@ -21,8 +21,7 @@ class WeekDateTimePickerSheet extends StatelessWidget {
final double weekDateBoxSize; final double weekDateBoxSize;
String _getDateHeader(BuildContext context) { String _getDateHeader(BuildContext context) {
var weekDays = var weekDays = dateTimePickerController.browsingDate.daysOfWeek();
dateTimePickerController.browsingDate.daysOfWeek();
var firstDay = weekDays.first.day.toString(); var firstDay = weekDays.first.day.toString();

View file

@ -1,6 +1,6 @@
name: flutter_date_time_picker name: flutter_date_time_picker
description: A Flutter package for date and time picker. description: A Flutter package for date and time picker.
version: 2.2.2 version: 2.2.3
homepage: https://iconica.nl/ homepage: https://iconica.nl/
environment: environment: