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
859b6ecd
Unverified
Commit
859b6ecd
authored
Mar 03, 2023
by
Hasnen Tai
Committed by
GitHub
Mar 03, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Feat: `showDatePicker` - Exposed callback when user changes Date Picker Mode (#119116)
parent
eaae56ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
date_picker.dart
packages/flutter/lib/src/material/date_picker.dart
+20
-0
date_picker_test.dart
packages/flutter/test/material/date_picker_test.dart
+18
-0
No files found.
packages/flutter/lib/src/material/date_picker.dart
View file @
859b6ecd
...
...
@@ -164,6 +164,7 @@ Future<DateTime?> showDatePicker({
String
?
fieldLabelText
,
TextInputType
?
keyboardType
,
Offset
?
anchorPoint
,
final
ValueChanged
<
DatePickerEntryMode
>?
onDatePickerModeChange
})
async
{
initialDate
=
DateUtils
.
dateOnly
(
initialDate
);
firstDate
=
DateUtils
.
dateOnly
(
firstDate
);
...
...
@@ -202,6 +203,7 @@ Future<DateTime?> showDatePicker({
fieldHintText:
fieldHintText
,
fieldLabelText:
fieldLabelText
,
keyboardType:
keyboardType
,
onDatePickerModeChange:
onDatePickerModeChange
,
);
if
(
textDirection
!=
null
)
{
...
...
@@ -259,6 +261,7 @@ class DatePickerDialog extends StatefulWidget {
this
.
fieldLabelText
,
this
.
keyboardType
,
this
.
restorationId
,
this
.
onDatePickerModeChange
})
:
initialDate
=
DateUtils
.
dateOnly
(
initialDate
),
firstDate
=
DateUtils
.
dateOnly
(
firstDate
),
lastDate
=
DateUtils
.
dateOnly
(
lastDate
),
...
...
@@ -356,6 +359,15 @@ class DatePickerDialog extends StatefulWidget {
/// Flutter.
final
String
?
restorationId
;
/// Called when the [DatePickerDialog] is toggled between
/// [DatePickerEntryMode.calendar],[DatePickerEntryMode.input].
///
/// An example of how this callback might be used is an app that saves the
/// user's preferred entry mode and uses it to initialize the
/// `initialEntryMode` parameter the next time the date picker is shown.
final
ValueChanged
<
DatePickerEntryMode
>?
onDatePickerModeChange
;
@override
State
<
DatePickerDialog
>
createState
()
=>
_DatePickerDialogState
();
}
...
...
@@ -394,16 +406,24 @@ class _DatePickerDialogState extends State<DatePickerDialog> with RestorationMix
Navigator
.
pop
(
context
);
}
void
_handleOnDatePickerModeChange
()
{
if
(
widget
.
onDatePickerModeChange
!=
null
)
{
widget
.
onDatePickerModeChange
!(
_entryMode
.
value
);
}
}
void
_handleEntryModeToggle
()
{
setState
(()
{
switch
(
_entryMode
.
value
)
{
case
DatePickerEntryMode
.
calendar
:
_autovalidateMode
.
value
=
AutovalidateMode
.
disabled
;
_entryMode
.
value
=
DatePickerEntryMode
.
input
;
_handleOnDatePickerModeChange
();
break
;
case
DatePickerEntryMode
.
input
:
_formKey
.
currentState
!.
save
();
_entryMode
.
value
=
DatePickerEntryMode
.
calendar
;
_handleOnDatePickerModeChange
();
break
;
case
DatePickerEntryMode
.
calendarOnly
:
case
DatePickerEntryMode
.
inputOnly
:
...
...
packages/flutter/test/material/date_picker_test.dart
View file @
859b6ecd
...
...
@@ -20,6 +20,7 @@ void main() {
late
SelectableDayPredicate
?
selectableDayPredicate
;
late
DatePickerEntryMode
initialEntryMode
;
late
DatePickerMode
initialCalendarMode
;
late
DatePickerEntryMode
currentMode
;
String
?
cancelText
;
String
?
confirmText
;
...
...
@@ -56,6 +57,7 @@ void main() {
fieldLabelText
=
null
;
helpText
=
null
;
keyboardType
=
null
;
currentMode
=
initialEntryMode
;
});
Future
<
void
>
prepareDatePicker
(
...
...
@@ -101,6 +103,9 @@ void main() {
fieldLabelText:
fieldLabelText
,
helpText:
helpText
,
keyboardType:
keyboardType
,
onDatePickerModeChange:
(
DatePickerEntryMode
value
)
{
currentMode
=
value
;
},
builder:
(
BuildContext
context
,
Widget
?
child
)
{
return
Directionality
(
textDirection:
textDirection
,
...
...
@@ -1369,6 +1374,19 @@ void main() {
expect
(
find
.
byType
(
TextField
),
findsNothing
);
expect
(
find
.
byIcon
(
Icons
.
edit
),
findsNothing
);
},
skip:
isBrowser
);
// https://github.com/flutter/flutter/issues/33615
testWidgets
(
'Test Callback on Toggle of DatePicker Mode'
,
(
WidgetTester
tester
)
async
{
prepareDatePicker
(
tester
,
(
Future
<
DateTime
?>
date
)
async
{
await
tester
.
tap
(
find
.
byIcon
(
Icons
.
edit
));
expect
(
currentMode
,
DatePickerEntryMode
.
input
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
TextField
),
findsOneWidget
);
await
tester
.
tap
(
find
.
byIcon
(
Icons
.
calendar_today
));
expect
(
currentMode
,
DatePickerEntryMode
.
calendar
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
TextField
),
findsNothing
);
});
});
}
class
_RestorableDatePickerDialogTestWidget
extends
StatefulWidget
{
...
...
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