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
2735a661
Unverified
Commit
2735a661
authored
Aug 19, 2020
by
Darren Austin
Committed by
GitHub
Aug 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes to initialDate for CalendarDatePicker should update the state. (#64115)
parent
2b67846a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
3 deletions
+84
-3
calendar_date_picker.dart
...lutter/lib/src/material/pickers/calendar_date_picker.dart
+28
-3
date_picker_test.dart
packages/flutter/test/material/date_picker_test.dart
+56
-0
No files found.
packages/flutter/lib/src/material/pickers/calendar_date_picker.dart
View file @
2735a661
...
@@ -12,6 +12,7 @@ import 'package:flutter/services.dart';
...
@@ -12,6 +12,7 @@ import 'package:flutter/services.dart';
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'../color_scheme.dart'
;
import
'../color_scheme.dart'
;
import
'../debug.dart'
;
import
'../divider.dart'
;
import
'../divider.dart'
;
import
'../icon_button.dart'
;
import
'../icon_button.dart'
;
import
'../icons.dart'
;
import
'../icons.dart'
;
...
@@ -164,14 +165,21 @@ class _CalendarDatePickerState extends State<CalendarDatePicker> {
...
@@ -164,14 +165,21 @@ class _CalendarDatePickerState extends State<CalendarDatePicker> {
@override
@override
void
initState
()
{
void
initState
()
{
super
.
initState
();
super
.
initState
();
_mode
=
widget
.
initialCalendarMode
;
_initWidgetState
();
_currentDisplayedMonthDate
=
DateTime
(
widget
.
initialDate
.
year
,
widget
.
initialDate
.
month
);
}
_selectedDate
=
widget
.
initialDate
;
@override
void
didUpdateWidget
(
CalendarDatePicker
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
_initWidgetState
();
}
}
@override
@override
void
didChangeDependencies
()
{
void
didChangeDependencies
()
{
super
.
didChangeDependencies
();
super
.
didChangeDependencies
();
assert
(
debugCheckHasMaterial
(
context
));
assert
(
debugCheckHasMaterialLocalizations
(
context
));
assert
(
debugCheckHasDirectionality
(
context
));
_localizations
=
MaterialLocalizations
.
of
(
context
);
_localizations
=
MaterialLocalizations
.
of
(
context
);
_textDirection
=
Directionality
.
of
(
context
);
_textDirection
=
Directionality
.
of
(
context
);
if
(!
_announcedInitialDate
)
{
if
(!
_announcedInitialDate
)
{
...
@@ -183,6 +191,12 @@ class _CalendarDatePickerState extends State<CalendarDatePicker> {
...
@@ -183,6 +191,12 @@ class _CalendarDatePickerState extends State<CalendarDatePicker> {
}
}
}
}
void
_initWidgetState
()
{
_mode
=
widget
.
initialCalendarMode
;
_currentDisplayedMonthDate
=
DateTime
(
widget
.
initialDate
.
year
,
widget
.
initialDate
.
month
);
_selectedDate
=
widget
.
initialDate
;
}
void
_vibrate
()
{
void
_vibrate
()
{
switch
(
Theme
.
of
(
context
).
platform
)
{
switch
(
Theme
.
of
(
context
).
platform
)
{
case
TargetPlatform
.
android
:
case
TargetPlatform
.
android
:
...
@@ -281,6 +295,9 @@ class _CalendarDatePickerState extends State<CalendarDatePicker> {
...
@@ -281,6 +295,9 @@ class _CalendarDatePickerState extends State<CalendarDatePicker> {
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
assert
(
debugCheckHasMaterialLocalizations
(
context
));
assert
(
debugCheckHasDirectionality
(
context
));
return
Stack
(
return
Stack
(
children:
<
Widget
>[
children:
<
Widget
>[
SizedBox
(
SizedBox
(
...
@@ -514,6 +531,14 @@ class _MonthPickerState extends State<_MonthPicker> {
...
@@ -514,6 +531,14 @@ class _MonthPickerState extends State<_MonthPicker> {
_textDirection
=
Directionality
.
of
(
context
);
_textDirection
=
Directionality
.
of
(
context
);
}
}
@override
void
didUpdateWidget
(
_MonthPicker
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
if
(
widget
.
initialMonth
!=
oldWidget
.
initialMonth
)
{
_showMonth
(
widget
.
initialMonth
);
}
}
@override
@override
void
dispose
()
{
void
dispose
()
{
_pageController
?.
dispose
();
_pageController
?.
dispose
();
...
...
packages/flutter/test/material/date_picker_test.dart
View file @
2735a661
...
@@ -825,6 +825,62 @@ void main() {
...
@@ -825,6 +825,62 @@ void main() {
});
});
});
});
group
(
'CalendarDatePicker'
,
()
{
// Tests for the standalone CalendarDatePicker class
testWidgets
(
'Updates to initialDate parameter is reflected in the state'
,
(
WidgetTester
tester
)
async
{
final
Key
pickerKey
=
UniqueKey
();
final
DateTime
initialDate
=
DateTime
(
2020
,
1
,
21
);
final
DateTime
updatedDate
=
DateTime
(
1976
,
2
,
23
);
const
Color
selectedColor
=
Color
(
0xff2196f3
);
// default primary color
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
CalendarDatePicker
(
key:
pickerKey
,
initialDate:
initialDate
,
firstDate:
DateTime
(
1970
,
1
,
1
),
lastDate:
DateTime
(
2099
,
31
,
12
),
onDateChanged:
(
DateTime
value
)
{},
),
),
));
await
tester
.
pumpAndSettle
();
// Month should show as January 2020
expect
(
find
.
text
(
'January 2020'
),
findsOneWidget
);
// Selected date should be painted with a colored circle
expect
(
Material
.
of
(
tester
.
element
(
find
.
text
(
'21'
))),
paints
..
circle
(
color:
selectedColor
,
style:
PaintingStyle
.
fill
)
);
// Change to the updated initialDate
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
CalendarDatePicker
(
key:
pickerKey
,
initialDate:
updatedDate
,
firstDate:
DateTime
(
1970
,
1
,
1
),
lastDate:
DateTime
(
2099
,
31
,
12
),
onDateChanged:
(
DateTime
value
)
{},
),
),
));
// Wait for the page scroll animation to finish
await
tester
.
pumpAndSettle
(
const
Duration
(
milliseconds:
200
));
// Month should show as February 1976
expect
(
find
.
text
(
'January 2020'
),
findsNothing
);
expect
(
find
.
text
(
'February 1976'
),
findsOneWidget
);
// Selected date should be painted with a colored circle
expect
(
Material
.
of
(
tester
.
element
(
find
.
text
(
'23'
))),
paints
..
circle
(
color:
selectedColor
,
style:
PaintingStyle
.
fill
)
);
});
});
group
(
'Haptic feedback'
,
()
{
group
(
'Haptic feedback'
,
()
{
const
Duration
hapticFeedbackInterval
=
Duration
(
milliseconds:
10
);
const
Duration
hapticFeedbackInterval
=
Duration
(
milliseconds:
10
);
FeedbackTester
feedback
;
FeedbackTester
feedback
;
...
...
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