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
c150c5a0
Unverified
Commit
c150c5a0
authored
Jun 08, 2022
by
Benjamin Lempereur
Committed by
GitHub
Jun 08, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TimePicker : Ability to define dialOnly / inputOnly modes (#104491)
parent
e6d31b9d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
14 deletions
+56
-14
time_picker.dart
packages/flutter/lib/src/material/time_picker.dart
+36
-13
time_picker_test.dart
packages/flutter/test/material/time_picker_test.dart
+20
-1
No files found.
packages/flutter/lib/src/material/time_picker.dart
View file @
c150c5a0
...
...
@@ -65,11 +65,25 @@ const ShapeBorder _kDefaultShape = RoundedRectangleBorder(borderRadius: _kDefaul
/// TimePickerEntryMode.input] mode, [TextField]s are displayed and the user
/// types in the time they wish to select.
enum
TimePickerEntryMode
{
/// Tapping/dragging on a clock dial.
/// User picks time from a clock dial.
///
/// Can switch to [input] by activating a mode button in the dialog.
dial
,
/// Text input.
/// User can input the time by typing it into text fields.
///
/// Can switch to [dial] by activating a mode button in the dialog.
input
,
/// User can only pick time from a clock dial.
///
/// There is no user interface to switch to another mode.
dialOnly
,
/// User can only input the time by typing it into text fields.
///
/// There is no user interface to switch to another mode.
inputOnly
}
/// Provides properties for rendering time picker header fragments.
...
...
@@ -2055,6 +2069,10 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
_autofocusMinute
.
value
=
false
;
_entryMode
.
value
=
TimePickerEntryMode
.
dial
;
break
;
case
TimePickerEntryMode
.
dialOnly
:
case
TimePickerEntryMode
.
inputOnly
:
FlutterError
(
'Can not change entry mode from
$_entryMode
'
);
break
;
}
});
}
...
...
@@ -2118,7 +2136,7 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
}
void
_handleOk
()
{
if
(
_entryMode
.
value
==
TimePickerEntryMode
.
input
)
{
if
(
_entryMode
.
value
==
TimePickerEntryMode
.
input
||
_entryMode
.
value
==
TimePickerEntryMode
.
inputOnly
)
{
final
FormState
form
=
_formKey
.
currentState
!;
if
(!
form
.
validate
())
{
setState
(()
{
_autovalidateMode
.
value
=
AutovalidateMode
.
always
;
});
...
...
@@ -2141,6 +2159,7 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
final
double
timePickerHeight
;
switch
(
_entryMode
.
value
)
{
case
TimePickerEntryMode
.
dial
:
case
TimePickerEntryMode
.
dialOnly
:
switch
(
orientation
)
{
case
Orientation
.
portrait
:
timePickerWidth
=
_kTimePickerWidthPortrait
;
...
...
@@ -2157,6 +2176,7 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
}
break
;
case
TimePickerEntryMode
.
input
:
case
TimePickerEntryMode
.
inputOnly
:
timePickerWidth
=
_kTimePickerWidthPortrait
;
timePickerHeight
=
_kTimePickerHeightInput
;
break
;
...
...
@@ -2177,6 +2197,7 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
final
Widget
actions
=
Row
(
children:
<
Widget
>[
const
SizedBox
(
width:
10.0
),
if
(
_entryMode
.
value
==
TimePickerEntryMode
.
dial
||
_entryMode
.
value
==
TimePickerEntryMode
.
input
)
IconButton
(
color:
TimePickerTheme
.
of
(
context
).
entryModeIconColor
??
theme
.
colorScheme
.
onSurface
.
withOpacity
(
theme
.
colorScheme
.
brightness
==
Brightness
.
dark
?
1.0
:
0.6
,
...
...
@@ -2214,6 +2235,7 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
final
Widget
picker
;
switch
(
_entryMode
.
value
)
{
case
TimePickerEntryMode
.
dial
:
case
TimePickerEntryMode
.
dialOnly
:
final
Widget
dial
=
Padding
(
padding:
orientation
==
Orientation
.
portrait
?
const
EdgeInsets
.
symmetric
(
horizontal:
36
,
vertical:
24
)
:
const
EdgeInsets
.
all
(
24
),
child:
ExcludeSemantics
(
...
...
@@ -2280,6 +2302,7 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
}
break
;
case
TimePickerEntryMode
.
input
:
case
TimePickerEntryMode
.
inputOnly
:
picker
=
Form
(
key:
_formKey
,
autovalidateMode:
_autovalidateMode
.
value
,
...
...
@@ -2313,7 +2336,7 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
backgroundColor:
TimePickerTheme
.
of
(
context
).
backgroundColor
??
theme
.
colorScheme
.
surface
,
insetPadding:
EdgeInsets
.
symmetric
(
horizontal:
16.0
,
vertical:
_entryMode
.
value
==
TimePickerEntryMode
.
input
?
0.0
:
24.0
,
vertical:
(
_entryMode
.
value
==
TimePickerEntryMode
.
input
||
_entryMode
.
value
==
TimePickerEntryMode
.
inputOnly
)
?
0.0
:
24.0
,
),
child:
AnimatedContainer
(
width:
dialogSize
.
width
,
...
...
packages/flutter/test/material/time_picker_test.dart
View file @
c150c5a0
...
...
@@ -1007,13 +1007,32 @@ void _testsInput() {
expect
(
find
.
text
(
errorInvalidText
),
findsOneWidget
);
});
testWidgets
(
'Can
toggle
to dial entry mode'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Can
switch from input
to dial entry mode'
,
(
WidgetTester
tester
)
async
{
await
mediaQueryBoilerplate
(
tester
,
true
,
entryMode:
TimePickerEntryMode
.
input
);
await
tester
.
tap
(
find
.
byIcon
(
Icons
.
access_time
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
TextField
),
findsNothing
);
});
testWidgets
(
'Can switch from dial to input entry mode'
,
(
WidgetTester
tester
)
async
{
await
mediaQueryBoilerplate
(
tester
,
true
);
await
tester
.
tap
(
find
.
byIcon
(
Icons
.
keyboard
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
TextField
),
findsWidgets
);
});
testWidgets
(
'Can not switch out of inputOnly mode'
,
(
WidgetTester
tester
)
async
{
await
mediaQueryBoilerplate
(
tester
,
true
,
entryMode:
TimePickerEntryMode
.
inputOnly
);
expect
(
find
.
byType
(
TextField
),
findsWidgets
);
expect
(
find
.
byIcon
(
Icons
.
access_time
),
findsNothing
);
});
testWidgets
(
'Can not switch out of dialOnly mode'
,
(
WidgetTester
tester
)
async
{
await
mediaQueryBoilerplate
(
tester
,
true
,
entryMode:
TimePickerEntryMode
.
dialOnly
);
expect
(
find
.
byType
(
TextField
),
findsNothing
);
expect
(
find
.
byIcon
(
Icons
.
keyboard
),
findsNothing
);
});
testWidgets
(
'Switching to dial entry mode triggers entry callback'
,
(
WidgetTester
tester
)
async
{
bool
triggeredCallback
=
false
;
...
...
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