Fingertips18 / scroll-wheel-date-picker

A Flutter package for a scrollable and flat perspective wheel-type date picker like in TikTok.
https://pub.dev/packages/scroll_wheel_date_picker
MIT License
4 stars 6 forks source link

Issue in setting correct dates to be displayed. #4

Closed Aryan2892 closed 5 months ago

Aryan2892 commented 5 months ago

I want to set the the date to be displayed as 1st january 13 years from now. How can I do it? even if i initialize it to DateTime(2013,1,1) this widget still shows 2nd FEB 2024. Can you please tell me what is wrong or how can I fix it?

final DateTime currentDate = DateTime.now();
final DateTime initialDate = DateTime(currentDate.year - 13, 1, 1); 

ScrollWheelDatePicker(
    initialDate: initialDate,
    startDate: initialDate,
    lastDate: currentDate,
    theme: CurveDatePickerTheme(
      wheelPickerHeight: 200.0,
      overlay: ScrollWheelDatePickerOverlay.highlight,
      itemTextStyle: GoogleFonts.urbanist(
        color: Theme.of(context).colorScheme.secondary,
        fontSize: 30,
        fontWeight: FontWeight.w800,
      ),
      monthFormat: MonthFormat.threeLetters,
      overlayColor: Theme.of(context).colorScheme.primary,
      overAndUnderCenterOpacity: 0.2,
    ),
    onSelectedItemChanged: (value) {
      Logger().d('Selected date: $value');
      setState(() {
        _selectedDate = value;
      });
    },
),
eyyubzademireli commented 5 months ago

For 13 years ago:

final initialDate = DateTime.now().subtract(const Duration(days: 13* 365))

For 13 years ago and 1st january:

final daysCount = now.difference(january1st).inDays;
DateTime.now().subtract(const Duration(days: (13* 365) + daysCount));
Fingertips18 commented 5 months ago

@Aryan2892 Kindly check if the issue still persists 2dd7e507c0931005c2359400c129e2f4d8093d08

Aryan2892 commented 5 months ago

For 13 years ago:

final initialDate = DateTime.now().subtract(const Duration(days: 13* 365))

For 13 years ago and 1st january:

final daysCount = now.difference(january1st).inDays;
DateTime.now().subtract(const Duration(days: (13* 365) + daysCount));

Hi, in final dayCount I am not finding how to implement now.difference is undefined for me. I initialized it like this accorinfg to my understanding of what now meant final DateTime now = DateTime.now(); But january1st is still undefined.

Aryan2892 commented 5 months ago

@Aryan2892 Kindly check if the issue still persists 2dd7e50

The issue that I am facing is that I when I scroll past the start date it gives this error: Last date must be after the initial date or DateTime.now(). 'package:scroll_wheel_date_picker/src/date_controller.dart': Failed assertion: line 50 pos 14: 'DateTime.now().isBefore(lastDate)'

    final DateTime currentDate = DateTime.now();
    final DateTime firstDate = DateTime(2011, 1, 1);
ScrollWheelDatePicker(
                initialDate: firstDate,
                startDate: firstDate,
                lastDate: currentDate,
                theme: CurveDatePickerTheme(
                  wheelPickerHeight: 200.0,
                  overlay: ScrollWheelDatePickerOverlay.highlight,
                  itemTextStyle: GoogleFonts.urbanist(
                    color: Theme.of(context).colorScheme.secondary,
                    fontSize: 30,
                    fontWeight: FontWeight.w800,
                  ),
                  monthFormat: MonthFormat.threeLetters,
                  overlayColor: Theme.of(context).colorScheme.primary,
                  overAndUnderCenterOpacity: 0.2,
                ),
                onSelectedItemChanged: (value) {
                  WidgetsBinding.instance.addPostFrameCallback((_) {
                    setState(() {
                      _selectedDate = value;
                    });
                  });
                },
              ),
Aryan2892 commented 5 months ago

Another error I am facing is that after screen loads the widget and I scroll upwards as in to go to previous months. It says widget cannot be marked as needing to build because the framework ' 'is already in the process of building widgets. A widget can be marked as ' 'needing to be built during the build phase only if one of its ancestors ' 'is currently building. This exception is allowed because the framework ' 'builds parent widgets before children, which means a dirty descendant ' 'will always be built. Otherwise, the framework might not visit this ' 'widget during this build phase.' specificaly when I scroll months, date and year are fine when I scroll but when I scroll months it shows error. Also I have set it to 3 letters but its showing entire month name.

Fingertips18 commented 5 months ago

@Aryan2892 Have you check this 2dd7e507c0931005c2359400c129e2f4d8093d08? If not, kindly clone and check if the issue has been resolved or not. I believe the assert error was fixed in that commit. Also open another issue if you found another one instead of populating it inside another issue, thanks!

Aryan2892 commented 5 months ago

@Aryan2892 Have you check this 2dd7e50? If not, kindly clone and check if the issue has been resolved or not. I believe the assert error was fixed in that commit. Also open another issue if you found another one instead of populating it inside another issue, thanks!

Okay, this fixes my original issue! Thank you so much!

Fingertips18 commented 5 months ago

@Aryan2892 cool. Will close this now, make sure to open another issue if you encounter another one.