Skip to content

Fix for fb: group with DateTime or TimeOfDay value and a validator as array#503

Open
DanyUP wants to merge 2 commits into
joanpablo:masterfrom
DanyUP:date-time-array-validators
Open

Fix for fb: group with DateTime or TimeOfDay value and a validator as array#503
DanyUP wants to merge 2 commits into
joanpablo:masterfrom
DanyUP:date-time-array-validators

Conversation

@DanyUP
Copy link
Copy Markdown

@DanyUP DanyUP commented Feb 9, 2026

Connection with issue(s)

Close #428

Solution description

Fixes a bug with FormBuilder: when creating a from group with a DateTime or TimeOfDay value and a validator using array syntax, the validator is not added to the created FormControl.

For example, when creating a form group like this:

final form = fb.group({
   'control': [DateTime.now(), Validators.required],
});

the resultant FormControl (named 'control' in the example) is missing the validator.

Screenshots or Videos

To Do

  • Check the original issue to confirm it is fully satisfied
  • Add solution description to help guide reviewers
  • Add unit test to verify new or fixed behaviour
  • If apply, add documentation to code properties and package readme

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @DanyUP, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a bug in FormBuilder that prevented validators from being applied to DateTime and TimeOfDay form controls when defined using array syntax. The fix ensures that validators are correctly passed during FormControl creation, and new unit tests have been added to confirm the expected behavior.

Highlights

  • Bug Fix: Addresses an issue where validators were not being correctly applied to FormControls created with DateTime or TimeOfDay values when using the array syntax in FormBuilder.
  • Implementation: The fix ensures that validators are now properly passed to FormControl constructors for DateTime and TimeOfDay types.
  • Testing: Includes new unit tests to verify the corrected behavior for both DateTime and TimeOfDay form controls.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • lib/src/models/form_builder.dart
    • Modified to pass validators to FormControl constructors for DateTime and TimeOfDay types.
  • test/src/models/form_builder_test.dart
    • Added new unit tests to verify that validators are correctly applied to DateTime and TimeOfDay form controls when using array syntax.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a bug where validators were not being applied to DateTime and TimeOfDay controls when using the array syntax in fb.group. The fix correctly passes the validators to the FormControl constructor, which is the right approach. The change is supported by new unit tests that verify the fix for both DateTime and TimeOfDay. The fix is correct and the tests are relevant. I've added a few suggestions to improve the new test code by using more idiomatic matchers, which will make them more concise and robust.

Comment on lines +424 to +429
expect(
form.control('control') is FormControl<DateTime>,
true,
reason:
'${form.control('control').runtimeType} is not instance of FormControl<DateTime>',
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For type checks in tests, it's more idiomatic to use the isA<T>() matcher. It provides better error messages on failure, especially if the control is null.

Suggested change
expect(
form.control('control') is FormControl<DateTime>,
true,
reason:
'${form.control('control').runtimeType} is not instance of FormControl<DateTime>',
);
expect(form.control('control'), isA<FormControl<DateTime>>());

Comment on lines +435 to +444
expect(
form.control('control').validators.length,
1,
reason: 'incorrect validators length'
);
expect(
form.control('control').validators[0],
requiredValidator,
reason: 'not set required validator'
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

You can simplify these two assertions into a single one by comparing the validators list directly. This is more concise and checks both the length and the content of the list.

Suggested change
expect(
form.control('control').validators.length,
1,
reason: 'incorrect validators length'
);
expect(
form.control('control').validators[0],
requiredValidator,
reason: 'not set required validator'
);
expect(form.control('control').validators, [requiredValidator]);

Comment on lines +479 to +484
expect(
form.control('control') is FormControl<TimeOfDay>,
true,
reason:
'${form.control('control').runtimeType} is not instance of FormControl<TimeOfDay>',
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For type checks in tests, it's more idiomatic to use the isA<T>() matcher. It provides better error messages on failure, especially if the control is null.

Suggested change
expect(
form.control('control') is FormControl<TimeOfDay>,
true,
reason:
'${form.control('control').runtimeType} is not instance of FormControl<TimeOfDay>',
);
expect(form.control('control'), isA<FormControl<TimeOfDay>>());

Comment on lines +490 to +499
expect(
form.control('control').validators.length,
1,
reason: 'incorrect validators length'
);
expect(
form.control('control').validators[0],
requiredValidator,
reason: 'not set required validator'
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

You can simplify these two assertions into a single one by comparing the validators list directly. This is more concise and checks both the length and the content of the list.

Suggested change
expect(
form.control('control').validators.length,
1,
reason: 'incorrect validators length'
);
expect(
form.control('control').validators[0],
requiredValidator,
reason: 'not set required validator'
);
expect(form.control('control').validators, [requiredValidator]);

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

Successfully merging this pull request may close these issues.

ReactiveDatePicker Validators not working when using fb syntax without FormControl()

1 participant