flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.42k stars 27.3k forks source link

selectableDayPredicate in DatePicker with EntryMode.input unexpectedly gets executed again after DatePicker already returned a date #105223

Open kjzl opened 2 years ago

kjzl commented 2 years ago

Steps to Reproduce (tested on Android and Web)

  1. Execute flutter run on the code sample
  2. Press the FloatingActionButton
  3. Press OK on the DatePickerDialog which is in Input Mode

Expected 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 State createState() => _MyHomePageState(); } class _MyHomePageState extends State { DateTime? dateTime; void _changeDate() { dateTime = null; showDatePicker( context: context, initialDate: DateTime.now(), firstDate: DateTime.now().subtract(const Duration(days: 10)), lastDate: DateTime.now(), initialEntryMode: DatePickerEntryMode.input, selectableDayPredicate: (date) { if (dateTime == null) { print("$date is selectable"); return true; } if (DateUtils.dateOnly(dateTime!) == date) { print("$date is NOT selectable"); return false; } print("$date is selectable"); return true; }).then((value) { setState(() { dateTime = value; print("#showDatePicker() returned with $dateTime"); }); }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const Text( 'selectedDate:', ), Text( '$dateTime', style: Theme.of(context).textTheme.headline4, ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: _changeDate, tooltip: 'change Date', child: const Icon(Icons.edit_calendar), ), ); } } ```
Logs ``` [ +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 [ ] ════════════════════════════════════════════════════════════════════════════════════════════════════ ``` ``` Analyzing input_datepicker_bug... info - Avoid `print` calls in production code - lib\main.dart:44:13 - avoid_print info - Avoid `print` calls in production code - lib\main.dart:48:13 - avoid_print info - Avoid `print` calls in production code - lib\main.dart:51:11 - avoid_print info - Avoid `print` calls in production code - lib\main.dart:56:9 - avoid_print 4 issues found. (ran in 2.0s) ``` ``` [√] Flutter (Channel stable, 3.0.1, on Microsoft Windows [Version 10.0.22000.675], locale de-DE) • Flutter version 3.0.1 at C:\Users\user\Documents\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision fb57da5f94 (2 weeks ago), 2022-05-19 15:50:29 -0700 • Engine revision caaafc5604 • Dart version 2.17.1 • DevTools version 2.12.2 [√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) • Android SDK at C:\Users\user\AppData\Local\Android\sdk • Platform android-32, build-tools 32.1.0-rc1 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [☠] Visual Studio - develop for Windows (the doctor check crashed) X Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at https://github.com/flutter/flutter/issues. X Exception: Bad UTF-8 encoding (U+FFFD; REPLACEMENT CHARACTER) found while decoding string: [ { "instanceId": "319072f8", "installDate": "2022-05-20T16:43:20Z", "installationName": "VisualStudio/17.2.1+32516.85", "installationPath": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community", "installationVersion": "17.2.32516.85", "productId": "Microsoft.VisualStudio.Product.Community", "productPath": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\IDE\\devenv.exe", "state": 4294967295, "isComplete": true, "isLaunchable": true, "isPrerelease": false, "isRebootRequired": false, "displayName": "Visual Studio Community 2022", "description": "Leistungsstarke IDE, kostenlos f�r Studenten, Open-Source-Mitwirkende und Einzelpersonen", "channelId": "VisualStudio.17.Release", "channelUri": "https://aka.ms/vs/17/release/channel", "enginePath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\resources\\app\\ServiceHub\\Services\\Microsoft.VisualStudio.Setup.Service", "installedChannelUri": "https://aka.ms/vs/17/release/channel", "releaseNotes": "https://docs.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.2#17.2.1", "thirdPartyNotices": "https://go.microsoft.com/fwlink/?LinkId=661288", "updateDate": "2022-05-20T16:43:20.926339Z", "catalog": { "buildBranch": "d17.2", "buildVersion": "17.2.32516.85", "id": "VisualStudio/17.2.1+32516.85", "localBuild": "build-lab", "manifestName": "VisualStudio", "manifestType": "installer", "productDisplayVersion": "17.2.1", "productLine": "Dev17", "productLineVersion": "2022", "productMilestone": "RTW", "productMilestoneIsPreRelease": "False", "productName": "Visual Studio", "productPatchVersion": "1", "productPreReleaseMilestoneSuffix": "1.0", "productSemanticVersion": "17.2.1+32516.85", "requiredEngineVersion": "3.2.2148.26540" }, "properties": { "campaignId": "2030:200dba40-a443-4998-9fa3-c8bf7577f589", "channelManifestId": "VisualStudio.17.Release/17.2.1+32516.85", "nickname": "", "setupEngineFilePath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\setup.exe" } } ] . The Flutter team would greatly appreciate if you could file a bug explaining exactly what you were doing when this happened: https://github.com/flutter/flutter/issues/new/choose The source bytes were: [91, 13, 10, 32, 32, 123, 13, 10, 32, 32, 32, 32, 34, 105, 110, 115, 116, 97, 110, 99, 101, 73, 100, 34, 58, 32, 34, 51, 49, 57, 48, 55, 50, 102, 56, 34, 44, 13, 10, 32, 32, 32, 32, 34, 105, 110, 115, 116, 97, 108, 108, 68, 97, 116, 101, 34, 58, 32, 34, 50, 48, 50, 50, 45, 48, 53, 45, 50, 48, 84, 49, 54, 58, 52, 51, 58, 50, 48, 90, 34, 44, 13, 10, 32, 32, 32, 32, 34, 105, 110, 115, 116, 97, 108, 108, 97, 116, 105, 111, 110, 78, 97, 109, 101, 34, 58, 32, 34, 86, 105, 115, 117, 97, 108, 83, 116, 117, 100, 105, 111, 47, 49, 55, 46, 50, 46, 49, 43, 51, 50, 53, 49, 54, 46, 56, 53, 34, 44, 13, 10, 32, 32, 32, 32, 34, 105, 110, 115, 116, 97, 108, 108, 97, 116, 105, 111, 110, 80, 97, 116, 104, 34, 58, 32, 34, 67, 58, 92, 92, 80, 114, 111, 103, 114, 97, 109, 32, 70, 105, 108, 101, 115, 92, 92, 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 86, 105, 115, 117, 97, 108, 32, 83, 116, 117, 100, 105, 111, 92, 92, 50, 48, 50, 50, 92, 92, 67, 111, 109, 109, 117, 110, 105, 116, 121, 34, 44, 13, 10, 32, 32, 32, 32, 34, 105, 110, 115, 116, 97, 108, 108, 97, 116, 105, 111, 110, 86, 101, 114, 115, 105, 111, 110, 34, 58, 32, 34, 49, 55, 46, 50, 46, 51, 50, 53, 49, 54, 46, 56, 53, 34, 44, 13, 10, 32, 32, 32, 32, 34, 112, 114, 111, 100, 117, 99, 116, 73, 100, 34, 58, 32, 34, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 86, 105, 115, 117, 97, 108, 83, 116, 117, 100, 105, 111, 46, 80, 114, 111, 100, 117, 99, 116, 46, 67, 111, 109, 109, 117, 110, 105, 116, 121, 34, 44, 13, 10, 32, 32, 32, 32, 34, 112, 114, 111, 100, 117, 99, 116, 80, 97, 116, 104, 34, 58, 32, 34, 67, 58, 92, 92, 80, 114, 111, 103, 114, 97, 109, 32, 70, 105, 108, 101, 115, 92, 92, 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 86, 105, 115, 117, 97, 108, 32, 83, 116, 117, 100, 105, 111, 92, 92, 50, 48, 50, 50, 92, 92, 67, 111, 109, 109, 117, 110, 105, 116, 121, 92, 92, 67, 111, 109, 109, 111, 110, 55, 92, 92, 73, 68, 69, 92, 92, 100, 101, 118, 101, 110, 118, 46, 101, 120, 101, 34, 44, 13, 10, 32, 32, 32, 32, 34, 115, 116, 97, 116, 101, 34, 58, 32, 52, 50, 57, 52, 57, 54, 55, 50, 57, 53, 44, 13, 10, 32, 32, 32, 32, 34, 105, 115, 67, 111, 109, 112, 108, 101, 116, 101, 34, 58, 32, 116, 114, 117, 101, 44, 13, 10, 32, 32, 32, 32, 34, 105, 115, 76, 97, 117, 110, 99, 104, 97, 98, 108, 101, 34, 58, 32, 116, 114, 117, 101, 44, 13, 10, 32, 32, 32, 32, 34, 105, 115, 80, 114, 101, 114, 101, 108, 101, 97, 115, 101, 34, 58, 32, 102, 97, 108, 115, 101, 44, 13, 10, 32, 32, 32, 32, 34, 105, 115, 82, 101, 98, 111, 111, 116, 82, 101, 113, 117, 105, 114, 101, 100, 34, 58, 32, 102, 97, 108, 115, 101, 44, 13, 10, 32, 32, 32, 32, 34, 100, 105, 115, 112, 108, 97, 121, 78, 97, 109, 101, 34, 58, 32, 34, 86, 105, 115, 117, 97, 108, 32, 83, 116, 117, 100, 105, 111, 32, 67, 111, 109, 109, 117, 110, 105, 116, 121, 32, 50, 48, 50, 50, 34, 44, 13, 10, 32, 32, 32, 32, 34, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 34, 58, 32, 34, 76, 101, 105, 115, 116, 117, 110, 103, 115, 115, 116, 97, 114, 107, 101, 32, 73, 68, 69, 44, 32, 107, 111, 115, 116, 101, 110, 108, 111, 115, 32, 102, 129, 114, 32, 83, 116, 117, 100, 101, 110, 116, 101, 110, 44, 32, 79, 112, 101, 110, 45, 83, 111, 117, 114, 99, 101, 45, 77, 105, 116, 119, 105, 114, 107, 101, 110, 100, 101, 32, 117, 110, 100, 32, 69, 105, 110, 122, 101, 108, 112, 101, 114, 115, 111, 110, 101, 110, 34, 44, 13, 10, 32, 32, 32, 32, 34, 99, 104, 97, 110, 110, 101, 108, 73, 100, 34, 58, 32, 34, 86, 105, 115, 117, 97, 108, 83, 116, 117, 100, 105, 111, 46, 49, 55, 46, 82, 101, 108, 101, 97, 115, 101, 34, 44, 13, 10, 32, 32, 32, 32, 34, 99, 104, 97, 110, 110, 101, 108, 85, 114, 105, 34, 58, 32, 34, 104, 116, 116, 112, 115, 58, 47, 47, 97, 107, 97, 46, 109, 115, 47, 118, 115, 47, 49, 55, 47, 114, 101, 108, 101, 97, 115, 101, 47, 99, 104, 97, 110, 110, 101, 108, 34, 44, 13, 10, 32, 32, 32, 32, 34, 101, 110, 103, 105, 110, 101, 80, 97, 116, 104, 34, 58, 32, 34, 67, 58, 92, 92, 80, 114, 111, 103, 114, 97, 109, 32, 70, 105, 108, 101, 115, 32, 40, 120, 56, 54, 41, 92, 92, 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 86, 105, 115, 117, 97, 108, 32, 83, 116, 117, 100, 105, 111, 92, 92, 73, 110, 115, 116, 97, 108, 108, 101, 114, 92, 92, 114, 101, 115, 111, 117, 114, 99, 101, 115, 92, 92, 97, 112, 112, 92, 92, 83, 101, 114, 118, 105, 99, 101, 72, 117, 98, 92, 92, 83, 101, 114, 118, 105, 99, 101, 115, 92, 92, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 86, 105, 115, 117, 97, 108, 83, 116, 117, 100, 105, 111, 46, 83, 101, 116, 117, 112, 46, 83, 101, 114, 118, 105, 99, 101, 34, 44, 13, 10, 32, 32, 32, 32, 34, 105, 110, 115, 116, 97, 108, 108, 101, 100, 67, 104, 97, 110, 110, 101, 108, 85, 114, 105, 34, 58, 32, 34, 104, 116, 116, 112, 115, 58, 47, 47, 97, 107, 97, 46, 109, 115, 47, 118, 115, 47, 49, 55, 47, 114, 101, 108, 101, 97, 115, 101, 47, 99, 104, 97, 110, 110, 101, 108, 34, 44, 13, 10, 32, 32, 32, 32, 34, 114, 101, 108, 101, 97, 115, 101, 78, 111, 116, 101, 115, 34, 58, 32, 34, 104, 116, 116, 112, 115, 58, 47, 47, 100, 111, 99, 115, 46, 109, 105, 99, 114, 111, 115, 111, 102, 116, 46, 99, 111, 109, 47, 101, 110, 45, 117, 115, 47, 118, 105, 115, 117, 97, 108, 115, 116, 117, 100, 105, 111, 47, 114, 101, 108, 101, 97, 115, 101, 115, 47, 50, 48, 50, 50, 47, 114, 101, 108, 101, 97, 115, 101, 45, 110, 111, 116, 101, 115, 45, 118, 49, 55, 46, 50, 35, 49, 55, 46, 50, 46, 49, 34, 44, 13, 10, 32, 32, 32, 32, 34, 116, 104, 105, 114, 100, 80, 97, 114, 116, 121, 78, 111, 116, 105, 99, 101, 115, 34, 58, 32, 34, 104, 116, 116, 112, 115, 58, 47, 47, 103, 111, 46, 109, 105, 99, 114, 111, 115, 111, 102, 116, 46, 99, 111, 109, 47, 102, 119, 108, 105, 110, 107, 47, 63, 76, 105, 110, 107, 73, 100, 61, 54, 54, 49, 50, 56, 56, 34, 44, 13, 10, 32, 32, 32, 32, 34, 117, 112, 100, 97, 116, 101, 68, 97, 116, 101, 34, 58, 32, 34, 50, 48, 50, 50, 45, 48, 53, 45, 50, 48, 84, 49, 54, 58, 52, 51, 58, 50, 48, 46, 57, 50, 54, 51, 51, 57, 90, 34, 44, 13, 10, 32, 32, 32, 32, 34, 99, 97, 116, 97, 108, 111, 103, 34, 58, 32, 123, 13, 10, 32, 32, 32, 32, 32, 32, 34, 98, 117, 105, 108, 100, 66, 114, 97, 110, 99, 104, 34, 58, 32, 34, 100, 49, 55, 46, 50, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 98, 117, 105, 108, 100, 86, 101, 114, 115, 105, 111, 110, 34, 58, 32, 34, 49, 55, 46, 50, 46, 51, 50, 53, 49, 54, 46, 56, 53, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 105, 100, 34, 58, 32, 34, 86, 105, 115, 117, 97, 108, 83, 116, 117, 100, 105, 111, 47, 49, 55, 46, 50, 46, 49, 43, 51, 50, 53, 49, 54, 46, 56, 53, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 108, 111, 99, 97, 108, 66, 117, 105, 108, 100, 34, 58, 32, 34, 98, 117, 105, 108, 100, 45, 108, 97, 98, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 109, 97, 110, 105, 102, 101, 115, 116, 78, 97, 109, 101, 34, 58, 32, 34, 86, 105, 115, 117, 97, 108, 83, 116, 117, 100, 105, 111, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 109, 97, 110, 105, 102, 101, 115, 116, 84, 121, 112, 101, 34, 58, 32, 34, 105, 110, 115, 116, 97, 108, 108, 101, 114, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 112, 114, 111, 100, 117, 99, 116, 68, 105, 115, 112, 108, 97, 121, 86, 101, 114, 115, 105, 111, 110, 34, 58, 32, 34, 49, 55, 46, 50, 46, 49, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 112, 114, 111, 100, 117, 99, 116, 76, 105, 110, 101, 34, 58, 32, 34, 68, 101, 118, 49, 55, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 112, 114, 111, 100, 117, 99, 116, 76, 105, 110, 101, 86, 101, 114, 115, 105, 111, 110, 34, 58, 32, 34, 50, 48, 50, 50, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 112, 114, 111, 100, 117, 99, 116, 77, 105, 108, 101, 115, 116, 111, 110, 101, 34, 58, 32, 34, 82, 84, 87, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 112, 114, 111, 100, 117, 99, 116, 77, 105, 108, 101, 115, 116, 111, 110, 101, 73, 115, 80, 114, 101, 82, 101, 108, 101, 97, 115, 101, 34, 58, 32, 34, 70, 97, 108, 115, 101, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 112, 114, 111, 100, 117, 99, 116, 78, 97, 109, 101, 34, 58, 32, 34, 86, 105, 115, 117, 97, 108, 32, 83, 116, 117, 100, 105, 111, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 112, 114, 111, 100, 117, 99, 116, 80, 97, 116, 99, 104, 86, 101, 114, 115, 105, 111, 110, 34, 58, 32, 34, 49, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 112, 114, 111, 100, 117, 99, 116, 80, 114, 101, 82, 101, 108, 101, 97, 115, 101, 77, 105, 108, 101, 115, 116, 111, 110, 101, 83, 117, 102, 102, 105, 120, 34, 58, 32, 34, 49, 46, 48, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 112, 114, 111, 100, 117, 99, 116, 83, 101, 109, 97, 110, 116, 105, 99, 86, 101, 114, 115, 105, 111, 110, 34, 58, 32, 34, 49, 55, 46, 50, 46, 49, 43, 51, 50, 53, 49, 54, 46, 56, 53, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 114, 101, 113, 117, 105, 114, 101, 100, 69, 110, 103, 105, 110, 101, 86, 101, 114, 115, 105, 111, 110, 34, 58, 32, 34, 51, 46, 50, 46, 50, 49, 52, 56, 46, 50, 54, 53, 52, 48, 34, 13, 10, 32, 32, 32, 32, 125, 44, 13, 10, 32, 32, 32, 32, 34, 112, 114, 111, 112, 101, 114, 116, 105, 101, 115, 34, 58, 32, 123, 13, 10, 32, 32, 32, 32, 32, 32, 34, 99, 97, 109, 112, 97, 105, 103, 110, 73, 100, 34, 58, 32, 34, 50, 48, 51, 48, 58, 50, 48, 48, 100, 98, 97, 52, 48, 45, 97, 52, 52, 51, 45, 52, 57, 57, 56, 45, 57, 102, 97, 51, 45, 99, 56, 98, 102, 55, 53, 55, 55, 102, 53, 56, 57, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 99, 104, 97, 110, 110, 101, 108, 77, 97, 110, 105, 102, 101, 115, 116, 73, 100, 34, 58, 32, 34, 86, 105, 115, 117, 97, 108, 83, 116, 117, 100, 105, 111, 46, 49, 55, 46, 82, 101, 108, 101, 97, 115, 101, 47, 49, 55, 46, 50, 46, 49, 43, 51, 50, 53, 49, 54, 46, 56, 53, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 110, 105, 99, 107, 110, 97, 109, 101, 34, 58, 32, 34, 34, 44, 13, 10, 32, 32, 32, 32, 32, 32, 34, 115, 101, 116, 117, 112, 69, 110, 103, 105, 110, 101, 70, 105, 108, 101, 80, 97, 116, 104, 34, 58, 32, 34, 67, 58, 92, 92, 80, 114, 111, 103, 114, 97, 109, 32, 70, 105, 108, 101, 115, 32, 40, 120, 56, 54, 41, 92, 92, 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 86, 105, 115, 117, 97, 108, 32, 83, 116, 117, 100, 105, 111, 92, 92, 73, 110, 115, 116, 97, 108, 108, 101, 114, 92, 92, 115, 101, 116, 117, 112, 46, 101, 120, 101, 34, 13, 10, 32, 32, 32, 32, 125, 13, 10, 32, 32, 125, 13, 10, 93, 13, 10] • #0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3) #1 Utf8Decoder.convert (package:flutter_tools/src/convert.dart:54:7) #2 Codec.decode (dart:convert/codec.dart:26:34) #3 _ProcessImpl._runAndWait.getOutput (dart:io-patch/process_patch.dart:498:23) #4 _ProcessImpl._runAndWait (dart:io-patch/process_patch.dart:506:9) #5 _runNonInteractiveProcessSync (dart:io-patch/process_patch.dart:632:18) #6 Process.runSync (dart:io-patch/process_patch.dart:68:12) #7 LocalProcessManager.runSync (package:process/src/interface/local_process_manager.dart:103:22) #8 ErrorHandlingProcessManager.runSync. (package:flutter_tools/src/base/error_handling_io.dart:712:24) #9 _runSync (package:flutter_tools/src/base/error_handling_io.dart:597:14) #10 ErrorHandlingProcessManager.runSync (package:flutter_tools/src/base/error_handling_io.dart:711:12) #11 _DefaultProcessUtils.runSync (package:flutter_tools/src/base/process.dart:373:51) #12 VisualStudio._visualStudioDetails (package:flutter_tools/src/windows/visual_studio.dart:314:51) #13 VisualStudio._usableVisualStudioDetails. (package:flutter_tools/src/windows/visual_studio.dart:373:33) #14 VisualStudio._usableVisualStudioDetails (package:flutter_tools/src/windows/visual_studio.dart:391:4) #15 VisualStudio._usableVisualStudioDetails (package:flutter_tools/src/windows/visual_studio.dart) #16 VisualStudio._bestVisualStudioDetails (package:flutter_tools/src/windows/visual_studio.dart:416:9) #17 VisualStudio.isInstalled (package:flutter_tools/src/windows/visual_studio.dart:36:27) #18 VisualStudioValidator.validate (package:flutter_tools/src/windows/visual_studio_validator.dart:29:23) #19 Doctor.startValidatorTasks. (package:flutter_tools/src/doctor.dart:216:72) #20 asyncGuard. (package:flutter_tools/src/base/async_guard.dart:111:32) #21 asyncGuard. (package:flutter_tools/src/base/async_guard.dart:109:18) #22 _rootRun (dart:async/zone.dart:1426:13) #23 _CustomZone.run (dart:async/zone.dart:1328:19) #24 _runZoned (dart:async/zone.dart:1861:10) #25 runZonedGuarded (dart:async/zone.dart:1849:12) #26 runZoned (dart:async/zone.dart:1780:12) • IntelliJ at C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2022.1.1 • Flutter plugin version 67.1.4 • Dart plugin version 221.5591.58 [√] VS Code (version 1.67.2) • VS Code at C:\Users\user\AppData\Local\Programs\Microsoft VS Code • Flutter extension can be installed from: https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [√] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22000.675] • Chrome (web) • chrome • web-javascript • Google Chrome 101.0.4951.67 • Edge (web) • edge • web-javascript • Microsoft Edge 101.0.1210.47 [√] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. ```
maheshj01 commented 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.

logs ``` Reload already in progress, ignoring request Restarted application in 474ms. flutter: 2022-06-03 00:00:00.000 is selectable flutter: 2022-06-03 00:00:00.000 is selectable flutter: 2022-06-03 00:00:00.000 is selectable flutter: 2022-06-03 00:00:00.000 is selectable flutter: 2022-06-03 00:00:00.000 is selectable flutter: #showDatePicker() returned with 2022-06-03 00:00:00.000 flutter: 2022-06-03 00:00:00.000 is NOT selectable ════════ Exception caught by widgets library ═══════════════════════════════════ The following assertion was thrown building DatePickerDialog(dirty, dependencies: [_InheritedTheme, UnmanagedRestorationScope, MediaQuery, _LocalizationsScope-[GlobalKey#64f34]], state: _DatePickerDialogState#7d1db): Provided initialDate 2022-06-03 00:00:00.000 must satisfy provided selectableDayPredicate. 'package:flutter/src/material/input_date_picker_form_field.dart': Failed assertion: line 80 pos 7: 'selectableDayPredicate == null || initialDate == null || selectableDayPredicate!(this.initialDate!)' Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause. In either case, please report this assertion by filing a bug on GitHub: https://github.com/flutter/flutter/issues/new?template=2_bug.md The relevant error-causing widget was MaterialApp When the exception was thrown, this was the stack #2 new InputDatePickerFormField #3 _DatePickerDialogState.build.inputDatePicker #4 _DatePickerDialogState.build #5 StatefulElement.build #6 ComponentElement.performRebuild #7 StatefulElement.performRebuild #8 Element.rebuild #9 BuildOwner.buildScope #10 WidgetsBinding.drawFrame #11 RendererBinding._handlePersistentFrameCallback #12 SchedulerBinding._invokeFrameCallback #13 SchedulerBinding.handleDrawFrame #14 SchedulerBinding._handleDrawFrame #15 _invoke (dart:ui/hooks.dart:148:13) #16 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:318:5) #17 _drawFrame (dart:ui/hooks.dart:115:31) (elided 2 frames from class _AssertionError) ════════════════════════════════════════════════════════════════════════════════ ```
flutter doctor -v (mac) ``` [✓] Flutter (Channel stable, 3.0.1, on macOS 12.3 21E230 darwin-arm, locale en-IN) • Flutter version 3.0.1 at /Users/mahesh/Documents/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision fb57da5f94 (3 days ago), 2022-05-19 15:50:29 -0700 • Engine revision caaafc5604 • Dart version 2.17.1 • DevTools version 2.12.2 [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/mahesh/Library/Android/sdk • Platform android-32, build-tools 31.0.0 • ANDROID_HOME = /Users/mahesh/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763) • All Android licenses accepted. [!] Xcode - develop for iOS and macOS (Xcode 13.2.1) • Xcode at /Applications/Xcode.app/Contents/Developer ! CocoaPods 1.10.2 out of date (1.11.0 is recommended). CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see https://flutter.dev/platform-plugins To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions. [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763) [✓] IntelliJ IDEA Community Edition (version 2021.2.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 61.2.4 • Dart plugin version 212.5080.8 [✓] VS Code (version 1.66.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.40.0 [✓] Connected device (4 available) • Redmi K20 Pro (mobile) • 192.168.1.2:5555 • android-arm64 • Android 11 (API 30) • iPhone 12 Pro (mobile) • 19FD0231-BFF0-441D-B584-AD94C4084525 • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-2 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 12.3 21E230 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 101.0.4951.64 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. ``` ``` [✓] Flutter (Channel master, 3.1.0-0.0.pre.1008, on macOS 12.3 21E230 darwin-arm, locale en-IN) • Flutter version 3.1.0-0.0.pre.1008 at /Users/mahesh/Documents/flutter_master • Upstream repository https://github.com/flutter/flutter.git • Framework revision c2cc31b198 (26 hours ago), 2022-05-30 05:23:08 -0400 • Engine revision 05efd25f05 • Dart version 2.18.0 (build 2.18.0-151.0.dev) • DevTools version 2.13.1 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4) • Android SDK at /Users/mahesh/Library/Android/sdk • Platform android-32, build-tools 33.0.0-rc4 • ANDROID_HOME = /Users/mahesh/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763) • All Android licenses accepted. [!] Xcode - develop for iOS and macOS (Xcode 13.2.1) • Xcode at /Applications/Xcode.app/Contents/Developer ! CocoaPods 1.10.2 out of date (1.11.0 is recommended). CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see https://flutter.dev/platform-plugins To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions. [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763) [✓] IntelliJ IDEA Community Edition (version 2021.2.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 61.2.4 • Dart plugin version 212.5080.8 [✓] VS Code (version 1.66.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.40.0 [✓] Connected device (4 available) • sdk gphone arm64 (mobile) • emulator-5554 • android-arm64 • Android 11 (API 30) (emulator) • iPhone 12 Pro (mobile) • 6AE1D692-DB57-4C3E-ADCA-66842182426B • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 12.3 21E230 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 102.0.5005.61 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. ```
TahaTesser commented 2 years ago

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.

https://github.com/flutter/flutter/blob/be0c1bd0f0cec3aa97c6be279b7beae9d0e8d6be/packages/flutter/lib/src/material/date_picker.dart#L386-L396