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

[FormBuilderDateTimePicker]: Got problem if initialDate is null and lastDate is years ago. #1368

Open
2 of 7 tasks
devon opened this issue Feb 13, 2024 · 0 comments
Open
2 of 7 tasks
Labels
bug Something isn't working

Comments

@devon
Copy link

devon commented Feb 13, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Package/Plugin version

9.2.1

Platforms

  • Android
  • iOS
  • Linux
  • MacOS
  • Web
  • Windows

Flutter doctor

Flutter doctor
Flutter (Channel stable, 3.16.9, on
    macOS 14.2.1 23C71 darwin-arm64, locale
    en-CA)
[✓] Xcode - develop for iOS and macOS (Xcode
    15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)

Minimal code example

Code sample
FormBuilderDateTimePicker(
  name: 'birthday',
  initialValue: null,
  firstDate: DateTime(1923, 1, 1),
  lastDate: DateTime(2006, 12, 31),
),

Current Behavior

Got error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:flutter/src/material/date_picker.dart': Failed assertion: line 201 pos 5: 'initialDate == null || !initialDate.isAfter(lastDate)': initialDate 2024-02-13 00:00:00.000 must be on or before lastDate 2006-12-31 00:00:00.000.

Expected Behavior

The code should work for a null initialDate.

Steps To Reproduce

Add the form:

FormBuilderDateTimePicker(
  name: 'birthday',
  initialValue: null,
  firstDate: DateTime(1923, 1, 1),
  lastDate: DateTime(2006, 12, 31),
),

And click the field to select a date.

Aditional information

In _showDatePicker, if there is no initialDate, it will set to DateTime.now():

  Future<DateTime?> _showDatePicker(
      BuildContext context, DateTime? currentValue) {
    return showDatePicker(
      context: context,
      selectableDayPredicate: widget.selectableDayPredicate,
      initialDatePickerMode: widget.initialDatePickerMode,
      initialDate: currentValue ?? widget.initialDate ?? DateTime.now(),
     ....

So, it can't pass the assert:

assert(
    initialDate == null || !initialDate.isAfter(lastDate),
    'initialDate $initialDate must be on or before lastDate $lastDate.',
  );
@devon devon added the bug Something isn't working label Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant