-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Conversation
this.decimal: false, | ||
}) : type = 2; | ||
|
||
final int type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs documentation
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(' |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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, ' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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')); | |||
}); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add tests for:
==
andhashCode
(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
There was a problem hiding this comment.
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.
* Support for decimal and signed numeric keyboard * Comments * Rebase. * Roll engine to dd6f46c
Fixes #14916.
Requires flutter/engine#4853.
Engine roll includes: