Open kjzl opened 2 years ago
Hi @kjzl, Thanks for filing the issue. I can see that selectableDayPredicate
is getting executed more than once. When showing the DatePicker dialog and also when the dialog is closed with the action buttons.
When closing the dialog with input mode, the form state is saved which rebuilds the widget as a result selectableDayPredicate
is called again.
Calendar mode doesn't have this issue because there is no Form
in that mode.
Steps to Reproduce (tested on Android and Web)
flutter run
on the code sampleExpected results: Just like in EntryMode.calendar no Exception will be thrown because selectableDayPredicate is not run after the Dialog returned a value.
Actual results: Exception is thrown because selectableDayPredicate is run once AFTER the Dialog in EntryMode.input returns the selected date
Code sample
```dart import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @override StateLogs
``` [ +4 ms] Debug service listening on ws://127.0.0.1:50783/VuR5hQuiboE=/ws [ ] Running with sound null safety [ +2 ms] To hot restart changes while running, press "r" or "R". [ ] For a more detailed help message, press "h". To quit, press "q". [ +1 ms] An Observatory debugger and profiler on Chrome is available at: http://127.0.0.1:50783/VuR5hQuiboE= [ +12 ms] Flutter Web Bootstrap: Programmatic [+1214 ms] The Flutter DevTools debugger and profiler on Chrome is available at: http://127.0.0.1:9101?uri=http://127.0.0.1:50783/VuR5hQuiboE= [+2097 ms] 2022-06-02 00:00:00.000 is selectable [ ] 2022-06-02 00:00:00.000 is selectable [ +18 ms] 2022-06-02 00:00:00.000 is selectable [+1697 ms] 2022-06-02 00:00:00.000 is selectable [ +1 ms] 2022-06-02 00:00:00.000 is selectable [ ] #showDatePicker() returned with 2022-06-02 00:00:00.000 [ +4 ms] 2022-06-02 00:00:00.000 is NOT selectable [ +219 ms] ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ [ +2 ms] The following assertion was thrown building DatePickerDialog(dirty, dependencies: [ ] [UnmanagedRestorationScope, _InheritedTheme, _LocalizationsScope-[GlobalKey#ab1d7], MediaQuery], [ +2 ms] state: _DatePickerDialogState#ab2b9): [ ] Assertion failed: [ ] file:///C:/Users/user/Documents/flutter/packages/flutter/lib/src/material/input_date_picker_form_field.dart:81:7 [ ] selectableDayPredicate == null || initialDate == null || selectableDayPredicate!(this.initialDate!) [ ] "Provided initialDate 2022-06-02 00:00:00.000 must satisfy provided selectableDayPredicate." [ ] The relevant error-causing widget was: [ ] MaterialApp MaterialApp:file:///C:/Users/user/IdeaProjects/input_datepicker_bug/lib/main.dart:12:12 [ +2 ms] When the exception was thrown, this was the stack: [ ] C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49 throw_ [ ] C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3 assertFailed [ ] packages/flutter/src/material/input_date_picker_form_field.dart 81:93 new [ ] packages/flutter/src/material/date_picker.dart 518:17 inputDatePicker [ ] packages/flutter/src/material/date_picker.dart 559:18 build [ ] packages/flutter/src/widgets/framework.dart 4919:27 build [ ] packages/flutter/src/widgets/framework.dart 4806:15 performRebuild [ ] packages/flutter/src/widgets/framework.dart 4977:11 performRebuild [ ] packages/flutter/src/widgets/framework.dart 4529:5 rebuild [ ] packages/flutter/src/widgets/framework.dart 2659:18 buildScope [ ] packages/flutter/src/widgets/binding.dart 891:9 drawFrame [ ] packages/flutter/src/rendering/binding.dart 370:5 [_handlePersistentFrameCallback] [ ] packages/flutter/src/scheduler/binding.dart 1146:15 [_invokeFrameCallback] [ ] packages/flutter/src/scheduler/binding.dart 1083:9 handleDrawFrame [ ] packages/flutter/src/scheduler/binding.dart 997:5 [_handleDrawFrame] [ ] C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/platform_dispatcher.dart 1090:13 invoke [ ] C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/platform_dispatcher.dart 160:5 invokeOnDrawFrame [ ] C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/initialization.dart 194:45