Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] date changes unintended #15

Closed
devii21 opened this issue Nov 9, 2020 · 9 comments
Closed

[BUG] date changes unintended #15

devii21 opened this issue Nov 9, 2020 · 9 comments

Comments

@devii21
Copy link

devii21 commented Nov 9, 2020

When changing the year, sometimes the month gets changed to a seemingly random month. Same with month/day.

To reproduce:

        DatePickerWidget(
            initialDate: DateTime.now(),
            firstDate: DateTime.now(),
            onChange: (value, _) {
              print(value.toString());
            }),
  • select next month (Dec)
  • select next year (2021)
    -> february gets selected

OR

  • select next month (Dec)
  • select first
  • select current month (Nov)
    -> 9th gets selected
@kfiross
Copy link
Owner

kfiross commented Nov 14, 2020

Hi, I'll look for it

@shabeenabarde
Copy link

shabeenabarde commented Nov 27, 2020

I am facing the same issue. But if i change my initial date from DateTime.now(). to lets say DateTime(2020), it works fine. But I do not want that because I do not want my users to be able to select back dates.

But when it is selected as DateTime.now(), and I select Dec 28th 2020, It Gives me the date of Dec 3rd, 2020...
But if I tap on the picker again, thats when it gets selected correctly. So on the first selection, it gives me a random number but on the second selection, it gives me the correct date.

Find my code below (The one that gives me incorrect date on first selection):

`
import 'package:flutter/material.dart';
import 'package:flutter_holo_date_picker/flutter_holo_date_picker.dart';
import 'package:intl/intl.dart';

class DateTesting extends StatefulWidget {
DateTesting({Key key}) : super(key: key);

@OverRide
_DateTestingState createState() => _DateTestingState();
}

class _DateTestingState extends State {
static DateTime startDate = DateTime.now();
String quoteStartDate =
DateFormat.yMMMd().format(startDate.add(Duration(days: 1))).toString();
String endPeriod = DateFormat.yMMMd()
.format(DateTime.now().add(Duration(days: 30)))
.toString();

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Date Testing",
),
),
body: ListView(
children: [
RaisedButton(
child: Text("$quoteStartDate"),
onPressed: () async {
var selectedFirstDate = await DatePicker.showSimpleDatePicker(
context,
initialDate: DateFormat.yMMMd().parse(quoteStartDate),
// firstDate: DateFormat.yMMMd().parse(quoteStartDate),
firstDate:
// startDate,
// DateTime(2020),
DateTime.now(),
lastDate: DateTime(2030),
dateFormat: "yyyy-MMMM-dd",
locale: DateTimePickerLocale.en_us,
looping: true,
);

            print("My date is picked $selectedFirstDate");

            setState(() {
              setState(() {
                quoteStartDate =
                    DateFormat.yMMMd().format(selectedFirstDate);

                print("My quoteStartDate is picked $quoteStartDate");

                endPeriod = DateFormat.yMMMd()
                    .format(selectedFirstDate.add(Duration(days: 30)))
                    .toString();
                // oneYear = selectedFirstDate.add(Duration(days: 29));
              });
            });
          },
        ),
        RaisedButton(
          child: Text("$endPeriod"),
          onPressed: () async {
            var selectedEndDate = await DatePicker.showSimpleDatePicker(
              context,
              initialDate: DateFormat.yMMMd().parse(endPeriod),
              firstDate: DateFormat.yMMMd()
                  .parse(endPeriod)
                  .subtract(Duration(days: 30)),
              lastDate: DateFormat.yMMMd()
                  .parse(quoteStartDate)
                  .add(Duration(days: 30)),
              dateFormat: "yyyy-MMMM-dd",
              locale: DateTimePickerLocale.en_us,
              looping: true,
            );

            setState(() {
              endPeriod =
                  DateFormat.yMMMd().format(selectedEndDate).toString();

            });

            print("My date is picked $selectedEndDate");
          },
        ),
      ],
    ));

}
}`

@kfiross
Copy link
Owner

kfiross commented Nov 29, 2020

If I got it right, when you change the month - the day is selected "randomly"?

@kfiross
Copy link
Owner

kfiross commented Nov 29, 2020

@devii21 @shabeenabarde I uploaded a dev version, please check it and tell if the bug is fixed

@shabeenabarde
Copy link

@kfiross I changed my channel to Dev, and the issue still persists. I don't know if i am going wrong somewhere.

This is my flutter doctor Summary:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, 1.24.0-10.2.pre, on Mac OS X 10.15.4 19E287 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
[✓] Android Studio (version 3.4)
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.51.1)
[✓] Connected device (1 available)
! Error: Shabeena’s iPhone is not connected. Xcode will continue when Shabeena’s iPhone is connected. (code -13)

@kfiross
Copy link
Owner

kfiross commented Nov 30, 2020

@shabeenabarde I meant the bug should be fixed in 0.3.0-dev
I tested it on Flutter beta channel 1.22

@shabeenabarde
Copy link

@kfiross It works fine with ^0.3.0-dev.1

@kfiross
Copy link
Owner

kfiross commented Nov 30, 2020

@shabeenabarde thanks! Issue closed.

@shabeenabarde
Copy link

shabeenabarde commented Dec 6, 2020

@kfiross

Kindly find the code below, I am facing a similar issue again:
`
import 'package:flutter/material.dart';
import 'package:flutter_holo_date_picker/flutter_holo_date_picker.dart';
import 'package:intl/intl.dart';

class DateTestingTwo extends StatefulWidget {
DateTestingTwo({Key key}) : super(key: key);

@OverRide
_DateTestingTwoState createState() => _DateTestingTwoState();
}

class _DateTestingTwoState extends State {
static DateTime startDate = DateTime.now();
String quoteStartDate = DateFormat.yMMMd().format(startDate);
String endPeriod = DateFormat.yMMMd()
.format(DateTime.now().add(Duration(days: 2)))
.toString();

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Date Testing 2",
),
),
body: ListView(
children: [
RaisedButton(
child: Text("$quoteStartDate"),
onPressed: () async {
try {
var selectedFirstDate = await DatePicker.showSimpleDatePicker(
context,
initialDate: DateFormat.yMMMd().parse(quoteStartDate),
firstDate: DateTime.now(),
lastDate: DateTime(2030),
dateFormat: "yyyy-MMMM-dd",
locale: DateTimePickerLocale.en_us,
looping: true,
);

              print("My date is picked $selectedFirstDate");

              setState(() {
                setState(() {
                  quoteStartDate =
                      DateFormat.yMMMd().format(selectedFirstDate);

                  print("My quoteStartDate is picked $quoteStartDate");
                });
              });
            } catch (e) {
              print("My error is $e");
            }
          },
        ),
        RaisedButton(
          child: Text("$endPeriod"),
          onPressed: () async {
            try {
              var selectedEndDate = await DatePicker.showSimpleDatePicker(
                context,
                initialDate: DateFormat.yMMMd().parse(endPeriod),
                firstDate: DateFormat.yMMMd()
                    .parse(quoteStartDate)
                    .subtract(Duration(days: 0)),
                lastDate: DateFormat.yMMMd()
                    .parse(quoteStartDate)
                    .add(Duration(days: 30)),
                dateFormat: "yyyy-MMMM-dd",
                locale: DateTimePickerLocale.en_us,
                looping: true,
              );

              setState(() {
                endPeriod =
                    DateFormat.yMMMd().format(selectedEndDate).toString();
              });

              print("My date is picked $selectedEndDate");
            } catch (e) {
              print("My error is $e");
            }
          },
        ),
      ],
    ));

}
}
`

Lets say my $quoteStartDate is 6th Dec 2020. So when i am choosing my $endPeriod, I want the firstDate of the $endPeriod to not go below the $quoteStartDate so I have set the firstDate for the $endPeriod to $quoteStartDate. So when i am choosing 6th Dec 2020 for $endPeriod, it automatically chooses 7th Dec 2020, I want it to be 6th Dec 2020 as selected. Why is that? I want the user to be able to select the $quoteStartDate and the $quoteEndDate as the same day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants