Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
eb941ce9
Unverified
Commit
eb941ce9
authored
Aug 11, 2020
by
Darren Austin
Committed by
GitHub
Aug 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed the inputFormatters from the text input fields used by the Date Pickers (#63461)
parent
df8e537f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
52 deletions
+7
-52
input_date_picker.dart
...s/flutter/lib/src/material/pickers/input_date_picker.dart
+5
-44
input_date_range_picker.dart
...ter/lib/src/material/pickers/input_date_range_picker.dart
+0
-7
date_picker_test.dart
packages/flutter/test/material/date_picker_test.dart
+2
-1
No files found.
packages/flutter/lib/src/material/pickers/input_date_picker.dart
View file @
eb941ce9
...
...
@@ -16,12 +16,12 @@ import '../theme.dart';
import
'date_picker_common.dart'
;
import
'date_utils.dart'
as
utils
;
/// A [TextFormField] configured to accept and validate a date entered by
the
user.
/// A [TextFormField] configured to accept and validate a date entered by
a
user.
///
///
The text entered into this field will be constrained to only allow digits
///
and separators. When saved or submitted, the text will be parsed into a
///
[DateTime] according to the ambient locale. If the input text doesn't parse
///
into a date, the [errorFormatText] message will
be displayed under the field.
///
When the field is saved or submitted, the text will be parsed into a
///
[DateTime] according to the ambient locale's compact date format. If the
///
input text doesn't parse into a date, the [errorFormatText] message will
/// be displayed under the field.
///
/// [firstDate], [lastDate], and [selectableDayPredicate] provide constraints on
/// what days are valid. If the input date isn't in the date range or doesn't pass
...
...
@@ -231,9 +231,6 @@ class _InputDatePickerFormFieldState extends State<InputDatePickerFormField> {
labelText:
widget
.
fieldLabelText
??
localizations
.
dateInputLabel
,
),
validator:
_validateDate
,
inputFormatters:
<
TextInputFormatter
>[
DateTextInputFormatter
(
localizations
.
dateSeparator
),
],
keyboardType:
TextInputType
.
datetime
,
onSaved:
_handleSaved
,
onFieldSubmitted:
_handleSubmitted
,
...
...
@@ -242,39 +239,3 @@ class _InputDatePickerFormFieldState extends State<InputDatePickerFormField> {
);
}
}
/// A `TextInputFormatter` set up to format dates.
//
// This is not publicly exported (see pickers.dart), as it is
// just meant for internal use by `InputDatePickerFormField` and
// `InputDateRangePicker`.
class
DateTextInputFormatter
extends
TextInputFormatter
{
/// Creates a date formatter with the given separator.
DateTextInputFormatter
(
this
.
separator
)
:
_filterFormatter
=
FilteringTextInputFormatter
.
allow
(
RegExp
(
'[
\\
d
$_commonSeparators
\\
$separator
]+'
));
/// List of common separators that are used in dates. This is used to make
/// sure that if given platform's [TextInputType.datetime] keyboard doesn't
/// provide the given locale's separator character, they can still enter the
/// separator using one of these characters (slash, period, comma, dash, or
/// space).
static
const
String
_commonSeparators
=
r'\/\.,-\s'
;
/// The date separator for the current locale.
final
String
separator
;
// Formatter that will filter out all characters except digits and date
// separators.
final
TextInputFormatter
_filterFormatter
;
@override
TextEditingValue
formatEditUpdate
(
TextEditingValue
oldValue
,
TextEditingValue
newValue
)
{
final
TextEditingValue
filteredValue
=
_filterFormatter
.
formatEditUpdate
(
oldValue
,
newValue
);
return
filteredValue
.
copyWith
(
// Replace any non-digits with the given separator
text:
filteredValue
.
text
.
replaceAll
(
RegExp
(
r'[\D]'
),
separator
),
);
}
}
packages/flutter/lib/src/material/pickers/input_date_range_picker.dart
View file @
eb941ce9
...
...
@@ -14,7 +14,6 @@ import '../text_field.dart';
import
'../theme.dart'
;
import
'date_utils.dart'
as
utils
;
import
'input_date_picker.dart'
show
DateTextInputFormatter
;
/// Provides a pair of text fields that allow the user to enter the start and
/// end dates that represent a range of dates.
...
...
@@ -124,7 +123,6 @@ class InputDateRangePickerState extends State<InputDateRangePicker> {
String
_startErrorText
;
String
_endErrorText
;
bool
_autoSelected
=
false
;
List
<
TextInputFormatter
>
_inputFormatters
;
@override
void
initState
()
{
...
...
@@ -146,9 +144,6 @@ class InputDateRangePickerState extends State<InputDateRangePicker> {
void
didChangeDependencies
()
{
super
.
didChangeDependencies
();
final
MaterialLocalizations
localizations
=
MaterialLocalizations
.
of
(
context
);
_inputFormatters
=
<
TextInputFormatter
>[
DateTextInputFormatter
(
localizations
.
dateSeparator
),
];
if
(
_startDate
!=
null
)
{
_startInputText
=
localizations
.
formatCompactDate
(
_startDate
);
final
bool
selectText
=
widget
.
autofocus
&&
!
_autoSelected
;
...
...
@@ -247,7 +242,6 @@ class InputDateRangePickerState extends State<InputDateRangePicker> {
labelText:
widget
.
fieldStartLabelText
??
localizations
.
dateRangeStartLabel
,
errorText:
_startErrorText
,
),
inputFormatters:
_inputFormatters
,
keyboardType:
TextInputType
.
datetime
,
onChanged:
_handleStartChanged
,
autofocus:
widget
.
autofocus
,
...
...
@@ -264,7 +258,6 @@ class InputDateRangePickerState extends State<InputDateRangePicker> {
labelText:
widget
.
fieldEndLabelText
??
localizations
.
dateRangeEndLabel
,
errorText:
_endErrorText
,
),
inputFormatters:
_inputFormatters
,
keyboardType:
TextInputType
.
datetime
,
onChanged:
_handleEndChanged
,
),
...
...
packages/flutter/test/material/date_picker_test.dart
View file @
eb941ce9
...
...
@@ -741,7 +741,8 @@ void main() {
field
.
controller
.
clear
();
await
tester
.
pumpAndSettle
();
await
tester
.
enterText
(
find
.
byType
(
TextField
),
'20202014'
);
await
tester
.
enterText
(
find
.
byType
(
TextField
),
'20 days, 3 months, 2003'
);
expect
(
find
.
text
(
'20 days, 3 months, 2003'
),
findsOneWidget
);
expect
(
find
.
text
(
errorFormatText
),
findsNothing
);
await
tester
.
tap
(
find
.
text
(
'OK'
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment