Skip to content

Added a few properties to make the field more flexible#1

Open
sarbogast wants to merge 4 commits into
jczhong:masterfrom
sarbogast:master
Open

Added a few properties to make the field more flexible#1
sarbogast wants to merge 4 commits into
jczhong:masterfrom
sarbogast:master

Conversation

@sarbogast

Copy link
Copy Markdown

The first thing that bothered me was that use24hFormat was hard-coded to false, even if DateFormat was 24-hour based. So that led to situations where time could be represented as 13:30 in the text field, but the date picker on iOS looked like 1:30 PM. So I exposed a use24hFormat property on the field itself so that the date picker can be adapted on iOS.

Another thing that bothered me was that I could not use the field as is in situations where the field value could be null, because if I set the initialValue to null, then it was replaced by DateTime.now().
So I changed that.
Now the default value for initialValue is null.
As a result, I added a nullText property to specify the text that appears in the text field when value is null.
And I also added a DateTime property called initialSelectionValue to specify which date the date picker or the date picker dialog should start with when the current value is null.
And last but not least I added a clearable property that, when true, adds a suffix button to the text field to reset the value to null.

@@ -1,2 +1,3 @@
org.gradle.jvmargs=-Xmx1536M

android.enableR8=true

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please don't include irrelevant files.

Comment thread example/pubspec.lock
version: "3.5.0"
sdks:
dart: ">=2.2.2 <3.0.0"
dart: ">=2.4.0 <3.0.0"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It's my mistake that I didn't add this file into .gitignore. It should not be include in repository.

/// So if current value is not null, then selection interface will start with
/// current value, otherwise it will look at initialSelectionValue, and if
/// this is null, then it will start with DateTime.now()
final DateTime initialSelectionValue;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

What's the differences between initialSelectionValue and intialValue? You can use initialValue instead of adding a new parameter.


/// Text that appears in the form field when the value is null, default is
/// 'Please pick a date/time'
final String nullText;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I suggest use hintText

),
child: Text(formatter.format(state.value)),
child: Text(
state.value != null ? formatter.format(state.value) : nullText),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I suggest add nullText to InputDecoration's hintText parameter.

date = await showDatePicker(
context: context,
initialDate: state.value,
initialDate: state.value ?? initialSelectionValue,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why not use initialValue?

Comment thread pubspec.lock
version: "3.5.0"
sdks:
dart: ">=2.2.2 <3.0.0"
dart: ">=2.4.0 <3.0.0"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please don't include this file.

@jczhong

jczhong commented Mar 28, 2020

Copy link
Copy Markdown
Owner

@sarbogast Hi Sarbogast, thank you so much for your great work!
The code looks good. You only need to make minor changes.

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.

2 participants