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

Support for decimal and signed numeric keyboard #15846

Merged
merged 5 commits into from
Mar 28, 2018
Merged

Support for decimal and signed numeric keyboard #15846

merged 5 commits into from
Mar 28, 2018

Conversation

sbaranov
Copy link
Contributor

@sbaranov sbaranov commented Mar 23, 2018

Fixes #14916.
Requires flutter/engine#4853.

Engine roll includes:

this.decimal: false,
}) : type = 2;

final int type;
Copy link
Contributor

Choose a reason for hiding this comment

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

needs documentation

Copy link
Contributor

Choose a reason for hiding this comment

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

or you could make it private.

Copy link
Contributor

Choose a reason for hiding this comment

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

if you leave it public, it should probably be called "index" to match enums.

final int type;

/// The number is signed, allowing a positive or negative sign at the start.
/// This flag is only used for numeric input type.
Copy link
Contributor

Choose a reason for hiding this comment

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

put a blank line between the sentences, so that only the first is considered part of the "brief" description

final bool signed;

/// The number is decimal, allowing a decimal point to provide fractional.
/// This flag is only used for numeric input type.
Copy link
Contributor

Choose a reason for hiding this comment

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

here and above, maybe instead of "numeric" use "[number]"?
also, maybe link to [new TextInputType.numberWithOptions] to say how to set this.

Copy link
Contributor

Choose a reason for hiding this comment

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

also maybe mention that it defaults to null if the type isn't number?

number,
/// Requests a default keyboard with ready access to the number keys.
/// Additional settings, such as decimal point and/or positive/negative
/// signs, can be requested by using the [numberWithOptions] constructor.
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you need [new TextInputType.numberWithOptions] to make that xref work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to confirm, using "new" here even though the actual usage is with "const"?

'text', 'multiline', 'number', 'phone', 'datetime', 'emailAddress', 'url',
];

/// Enum value name, this is what enum.toString() would normally return.
Copy link
Contributor

Choose a reason for hiding this comment

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

// not /// since this isn't documentation we would want to make public, it's a comment.

Copy link
Contributor Author

@sbaranov sbaranov Mar 23, 2018

Choose a reason for hiding this comment

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

FYI, style guide says "Use /// for public-quality private documentation".

}

@override
String toString() => '$runtimeType('
Copy link
Contributor

Choose a reason for hiding this comment

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

avoid => with multiline expressions in general (we make some exceptions in build methods where the result is more readable)


@override
bool operator ==(dynamic other) {
if (identical(this, other))
Copy link
Contributor

Choose a reason for hiding this comment

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

you probably don't need this identical check, this is a very cheap set of values to compare

Copy link
Contributor

Choose a reason for hiding this comment

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

(i don't have a good intuition about whether it's worth including the identical checks or not. In general we have tended to start by not including them, then add them when it becomes obvious that the normal path is starting to be a bit heavy.)


@override
int get hashCode => hashValues(
type.hashCode,
Copy link
Contributor

Choose a reason for hiding this comment

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

just pass in the value, not the value's hashCode. Did you find this pattern somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Blindly copied from where it used complex object.

int get hashCode => hashValues(
type.hashCode,
signed.hashCode,
decimal.hashCode
Copy link
Contributor

Choose a reason for hiding this comment

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

indent by 2 rather than 4.

This is a case where => looks ok, though we usually would either do it all on one line, or use a block with return.


@override
String toString() => '$runtimeType('
'type: \u2524$_name\u251C, '
Copy link
Contributor

Choose a reason for hiding this comment

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

that's surprisingly fancy, why not just inline the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied from another class down below, assumed it's some kind of convention on the team. Will happily change to plain format.

obscureText: true,
autocorrect: false,
actionLabel: 'xyzzy'
inputType: TextInputType.text,
Copy link
Contributor

Choose a reason for hiding this comment

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

indent by 2

inputType: TextInputType.text,
obscureText: true,
autocorrect: false,
actionLabel: 'xyzzy'
Copy link
Contributor

Choose a reason for hiding this comment

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

fwiw: if you're using dartfmt, it usually does a better job when you give trailing commas

@@ -161,7 +160,7 @@ void main() {
controller.text = 'test';
await tester.idle();
expect(tester.testTextInput.editingState['text'], equals('test'));
expect(tester.testTextInput.setClientArgs['inputType'], equals('TextInputType.text'));
expect(tester.testTextInput.setClientArgs['inputType']['type'], equals('TextInputType.text'));
expect(tester.testTextInput.setClientArgs['inputAction'], equals('TextInputAction.done'));
});

Copy link
Contributor

Choose a reason for hiding this comment

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

add tests for:

  • == and hashCode (not the specific code, just that it's the same when == is the same, and different otherwise)
  • toString
  • that signed and decimal can both be set, that they default to false for number and null for non-number

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in text_field.test.dart.

@Hixie
Copy link
Contributor

Hixie commented Mar 23, 2018

LGTM

@cbracken
Copy link
Member

lgtm

@sbaranov sbaranov merged commit c5288c7 into flutter:master Mar 28, 2018
@sbaranov sbaranov deleted the numeric_keyboard branch March 28, 2018 15:33
DaveShuckerow pushed a commit to DaveShuckerow/flutter that referenced this pull request May 14, 2018
* Support for decimal and signed numeric keyboard

* Comments

* Rebase.

* Roll engine to dd6f46c
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support numberDecimal and numberSigned keyboard type
4 participants