Unverified Commit 8b889d35 authored by Michael Debertol's avatar Michael Debertol Committed by GitHub

[DatePicker] Don't jump to the current month (#77739)

parent aaa7f842
......@@ -531,7 +531,7 @@ class _MonthPickerState extends State<_MonthPicker> {
@override
void didUpdateWidget(_MonthPicker oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.initialMonth != oldWidget.initialMonth) {
if (widget.initialMonth != oldWidget.initialMonth && widget.initialMonth != _currentMonth) {
// We can't interrupt this widget build with a scroll, so do it next frame
WidgetsBinding.instance!.addPostFrameCallback(
(Duration timeStamp) => _showMonth(widget.initialMonth, jump: true)
......
......@@ -431,6 +431,26 @@ void main() {
expect(find.text('2016'), findsNothing); // 2016 in year grid
});
testWidgets('Dragging more than half the width should not cause a jump', (
WidgetTester tester) async {
await tester.pumpWidget(calendarDatePicker());
await tester.pumpAndSettle();
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(PageView)));
// This initial drag is required for the PageView to recognize the gesture, as it uses DragStartBehavior.start.
// It does not count towards the drag distance.
await gesture.moveBy(const Offset(100, 0));
// Dragging for a bit less than half the width should reveal the previous month.
await gesture.moveBy(const Offset(800 / 2 - 1, 0));
await tester.pumpAndSettle();
expect(find.text('January 2016'), findsOneWidget);
expect(find.text('1'), findsNWidgets(2));
// Dragging a bit over the half should still show both.
await gesture.moveBy(const Offset(2, 0));
await tester.pumpAndSettle();
expect(find.text('December 2015'), findsOneWidget);
expect(find.text('1'), findsNWidgets(2));
});
group('Keyboard navigation', () {
testWidgets('Can toggle to year mode', (WidgetTester tester) async {
await tester.pumpWidget(calendarDatePicker());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment