Skip to content

Conversation

lucasbstn
Copy link

@lucasbstn lucasbstn commented Apr 20, 2025

Adds a new showSeconds property to ShadTimePicker.
Most times, when I want to ask a user for a time, seconds are irrelevant.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read and followed the Flutter Style Guide.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making.
  • I followed the Data Driven Fixes where supported.
  • All existing and new tests are passing.

If you need help, consider asking for advice on Discord.

Summary by CodeRabbit

  • New Features
    • Added an option to show or hide the seconds input field in the time picker.
  • Improvements
    • Time picker now defaults seconds to 0 if not specified.
    • Enhanced focus behavior when navigating between time fields, adapting to the visibility of the seconds input.

Copy link
Contributor

coderabbitai bot commented Apr 20, 2025

Walkthrough

The changes modify the time picker component to make the seconds field optional both in its data model and user interface. The ShadTimeOfDay class now treats the second parameter as optional, defaulting to 0. A new showSeconds boolean property is introduced to the ShadTimePicker widget and its constructors, allowing consumers to control whether the seconds input field is displayed. The internal state and focus management logic are updated to handle the presence or absence of the seconds field, ensuring consistent value construction and user interaction. Corresponding updates propagate the showSeconds parameter to the ShadTimePickerFormField and its named constructors.

Changes

File(s) Change Summary
lib/src/components/time_picker.dart Made second parameter in ShadTimeOfDay optional with default 0; added showSeconds property to ShadTimePicker and its constructors; updated UI and focus logic to conditionally show and handle seconds input; adjusted value construction and validation to accommodate optional seconds.
lib/src/components/form/fields/time_picker.dart Added showSeconds boolean parameter (default true) to ShadTimePickerFormField and its named constructors; passed showSeconds to underlying ShadTimePicker instances to control seconds field visibility.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ShadTimePicker
    participant ShadTimePickerController
    participant ShadTimeOfDay

    User->>ShadTimePicker: Interacts with Time Picker UI
    ShadTimePicker->>ShadTimePicker: Checks showSeconds property
    alt showSeconds = true
        ShadTimePicker->>User: Displays hour, minute, and seconds fields
        User->>ShadTimePicker: Enters hour, minute, second
        ShadTimePicker->>ShadTimeOfDay: Constructs with hour, minute, second
    else showSeconds = false
        ShadTimePicker->>User: Displays hour and minute fields only
        User->>ShadTimePicker: Enters hour, minute
        ShadTimePicker->>ShadTimeOfDay: Constructs with hour, minute, second=0
    end
    ShadTimePicker->>ShadTimePickerController: Updates value
Loading

Poem

In the meadow of time, the picker hops free,
Now seconds are optional, as simple as can be.
With a tick or a tock, you choose what you need,
Hours and minutes, or seconds indeed!
A hop, a skip, through focus it flows—
The picker adapts, wherever time goes!
🕰️🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b4e4da and f49bf64.

📒 Files selected for processing (1)
  • lib/src/components/time_picker.dart (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/src/components/time_picker.dart
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Flutter test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
lib/src/components/time_picker.dart (1)

1-1203: 💡 Verification agent

🧩 Analysis chain

Consider adding test coverage for the new showSeconds functionality

The PR objectives mention that all existing and new tests pass, but no new tests were added specifically for this change. Consider adding tests that:

  1. Verify the time picker works correctly when showSeconds is false
  2. Validate focus management behavior in both cases
  3. Ensure value construction is correct with/without seconds

This would help ensure the feature remains stable with future changes.


🏁 Script executed:

#!/bin/bash
# Search for existing tests related to time picker
rg -A 2 -B 2 "ShadTimePicker|time_picker_test" --glob="**/*test*.dart"

Length of output: 788


Add targeted tests for showSeconds behavior

Although there’s an existing golden test for ShadTimePicker, we’re missing unit/widget tests that specifically cover the new showSeconds flag. Please add tests to verify:

  • The number of input fields changes when showSeconds is false (no seconds field).
  • Focus traversal jumps correctly:
    • From minutes → trailing widget or AM/PM selector when showSeconds = false.
    • From minutes → seconds → AM/PM when showSeconds = true.
  • The onChanged callback builds the correct ShadTimeOfDay:
    • When showSeconds = false, seconds default to 0.
    • When showSeconds = true, seconds reflect the entered value.

This will ensure the feature remains robust to future changes.

🧹 Nitpick comments (1)
lib/src/components/time_picker.dart (1)

819-823: Consider adding a comment explaining the focus management logic

While the implementation is correct, a brief comment explaining the focus management logic would help future developers understand the intention behind this code.

  if (v.length == 2 &&
      effectiveJumpToNextField &&
      widget.variant == ShadTimePickerVariant.period) {
+   // Move focus to period selector after entering seconds
    periodFocusNode.requestFocus();
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba14059 and 5b37f03.

📒 Files selected for processing (1)
  • lib/src/components/time_picker.dart (8 hunks)
🔇 Additional comments (8)
lib/src/components/time_picker.dart (8)

20-20: Good change: Made second parameter optional with default value of 0

This change correctly makes the second parameter optional in the ShadTimeOfDay constructor, which aligns with the PR objective of making seconds optional in the time picker.


152-156: Change is aligned with the constructor update

Removing the null check for second in the conditional return and defaulting it to 0 when constructing the ShadTimeOfDay object is consistent with the constructor changes.


240-240: Good implementation: Added showSeconds parameter to all constructors

The showSeconds parameter with a default value of true has been consistently added to all three constructor variants of the ShadTimePicker widget.

Also applies to: 290-290, 336-336


339-342: Well-documented new property

The documentation for the new showSeconds property is clear and follows the existing documentation style with template macros.


643-644: Correctly updated validation logic

The validation logic now only checks if second is null when showSeconds is true, which is consistent with making seconds optional.


654-654: Proper null handling for seconds value

Using the null-coalescing operator to default second to 0 when it's null ensures consistent behavior when seconds are not specified.


793-797: Smart focus management implementation

The updated focus traversal logic correctly handles two cases:

  1. When seconds are shown, focus moves to the seconds field
  2. When seconds are hidden and the picker is in period mode, focus jumps directly to the period selector

This ensures a smooth user experience regardless of the showSeconds setting.


802-825: Good UI implementation: Conditional rendering of seconds field

The seconds input field is now conditionally rendered based on the showSeconds property, which completes the implementation of making seconds optional in the UI.

Copy link
Owner

@nank1ro nank1ro left a comment

Choose a reason for hiding this comment

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

@lucasbstn What about making each field optional? By default all are shown, but a show* is available for every input field

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.

3 participants