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
a31e0a43
Unverified
Commit
a31e0a43
authored
Sep 15, 2021
by
Parker Stromberg
Committed by
GitHub
Sep 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added time picker entry mode callback and tests (#87595)
parent
e7df5ec5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
1 deletion
+50
-1
time_picker.dart
packages/flutter/lib/src/material/time_picker.dart
+19
-0
time_picker_test.dart
packages/flutter/test/material/time_picker_test.dart
+31
-1
No files found.
packages/flutter/lib/src/material/time_picker.dart
View file @
a31e0a43
...
...
@@ -1786,6 +1786,9 @@ class _HourMinuteTextFieldState extends State<_HourMinuteTextField> with Restora
}
}
/// Signature for when the time picker entry mode is changed.
typedef
EntryModeChangeCallback
=
void
Function
(
TimePickerEntryMode
);
/// A material design time picker designed to appear inside a popup dialog.
///
/// Pass this widget to [showDialog]. The value returned by [showDialog] is the
...
...
@@ -1807,6 +1810,7 @@ class TimePickerDialog extends StatefulWidget {
this
.
minuteLabelText
,
this
.
restorationId
,
this
.
initialEntryMode
=
TimePickerEntryMode
.
dial
,
this
.
onEntryModeChanged
,
})
:
assert
(
initialTime
!=
null
),
super
(
key:
key
);
...
...
@@ -1852,6 +1856,9 @@ class TimePickerDialog extends StatefulWidget {
/// Flutter.
final
String
?
restorationId
;
/// Callback called when the selected entry mode is changed.
final
EntryModeChangeCallback
?
onEntryModeChanged
;
@override
State
<
TimePickerDialog
>
createState
()
=>
_TimePickerDialogState
();
}
...
...
@@ -1947,6 +1954,8 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
final
RestorableBoolN
_autofocusMinute
=
RestorableBoolN
(
null
);
final
RestorableBool
_announcedInitialTime
=
RestorableBool
(
false
);
late
final
VoidCallback
_entryModeListener
;
@override
void
didChangeDependencies
()
{
super
.
didChangeDependencies
();
...
...
@@ -1955,6 +1964,13 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
_announceModeOnce
();
}
@override
void
initState
()
{
super
.
initState
();
_entryModeListener
=
()
=>
widget
.
onEntryModeChanged
?.
call
(
_entryMode
.
value
);
_entryMode
.
addListener
(
_entryModeListener
);
}
@override
String
?
get
restorationId
=>
widget
.
restorationId
;
...
...
@@ -2288,6 +2304,7 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
void
dispose
()
{
_vibrateTimer
?.
cancel
();
_vibrateTimer
=
null
;
_entryMode
.
removeListener
(
_entryModeListener
);
super
.
dispose
();
}
}
...
...
@@ -2380,6 +2397,7 @@ Future<TimeOfDay?> showTimePicker({
String
?
hourLabelText
,
String
?
minuteLabelText
,
RouteSettings
?
routeSettings
,
EntryModeChangeCallback
?
onEntryModeChanged
,
})
async
{
assert
(
context
!=
null
);
assert
(
initialTime
!=
null
);
...
...
@@ -2396,6 +2414,7 @@ Future<TimeOfDay?> showTimePicker({
errorInvalidText:
errorInvalidText
,
hourLabelText:
hourLabelText
,
minuteLabelText:
minuteLabelText
,
onEntryModeChanged:
onEntryModeChanged
,
);
return
showDialog
<
TimeOfDay
>(
context:
context
,
...
...
packages/flutter/test/material/time_picker_test.dart
View file @
a31e0a43
...
...
@@ -903,6 +903,34 @@ void _testsInput() {
expect
(
find
.
byType
(
TextField
),
findsNothing
);
});
testWidgets
(
'Switching to dial entry mode triggers entry callback'
,
(
WidgetTester
tester
)
async
{
bool
triggeredCallback
=
false
;
await
mediaQueryBoilerplate
(
tester
,
true
,
entryMode:
TimePickerEntryMode
.
input
,
onEntryModeChange:
(
TimePickerEntryMode
mode
)
{
if
(
mode
==
TimePickerEntryMode
.
dial
)
{
triggeredCallback
=
true
;
}
});
await
tester
.
tap
(
find
.
byIcon
(
Icons
.
access_time
));
await
tester
.
pumpAndSettle
();
expect
(
triggeredCallback
,
true
);
});
testWidgets
(
'Switching to input entry mode triggers entry callback'
,
(
WidgetTester
tester
)
async
{
bool
triggeredCallback
=
false
;
await
mediaQueryBoilerplate
(
tester
,
true
,
entryMode:
TimePickerEntryMode
.
dial
,
onEntryModeChange:
(
TimePickerEntryMode
mode
)
{
if
(
mode
==
TimePickerEntryMode
.
input
)
{
triggeredCallback
=
true
;
}
});
await
tester
.
tap
(
find
.
byIcon
(
Icons
.
keyboard
));
await
tester
.
pumpAndSettle
();
expect
(
triggeredCallback
,
true
);
});
testWidgets
(
'Can double tap hours (when selected) to enter input mode'
,
(
WidgetTester
tester
)
async
{
await
mediaQueryBoilerplate
(
tester
,
false
,
entryMode:
TimePickerEntryMode
.
dial
);
final
Finder
hourFinder
=
find
.
ancestor
(
...
...
@@ -1163,6 +1191,7 @@ Future<void> mediaQueryBoilerplate(
String
?
minuteLabelText
,
String
?
errorInvalidText
,
bool
accessibleNavigation
=
false
,
EntryModeChangeCallback
?
onEntryModeChange
,
})
async
{
await
tester
.
pumpWidget
(
Localizations
(
...
...
@@ -1192,7 +1221,8 @@ Future<void> mediaQueryBoilerplate(
helpText:
helpText
,
hourLabelText:
hourLabelText
,
minuteLabelText:
minuteLabelText
,
errorInvalidText:
errorInvalidText
errorInvalidText:
errorInvalidText
,
onEntryModeChanged:
onEntryModeChange
,
);
},
child:
const
Text
(
'X'
),
...
...
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