Flutter 'showDatePicker' throws exception: Error: Expected a value of type 'String', but got one of type 'Null'
Solution 1
EDIT: This has been fixed in the master channel and will release soon
I filed a bug for this: https://github.com/flutter/flutter/issues/79834
This is caused by the framework internally calling HapticFeedback.vibrate()
for a fun little buzz when you tap pretty much anything in the pop-up window. However, on Web, this doesn't work. There is a switch-case to try to see if the platform supports it, but Web never got a proper TargetPlatform
, so the code thinks computers can vibrate.
When Flutter tries sending a message to the web engine, the null error happens.
Solution 2
I see the same using the latest flutter for web. It looks like the error is within the datepicker itself, not my code? The datepicker still seems to function as expected despite the error message showing in the debug consol?.
Dorin Balan
Updated on December 28, 2022Comments
-
Dorin Balan over 1 year
TextButton( onPressed: () => _showPicker(context), child: Icon(Icons.calendar_today), ) Future<DateTime?> _showPicker(BuildContext context) { return showDatePicker( context: context, initialDate: DateTime(2000), firstDate: DateTime(1990), lastDate: DateTime(2100)); }
The
DatePicker
pops up, but when you try to select a date or year it throws: Expected a value of type 'String', but got one of type 'Null'Flutter 2.0.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision 4d7946a68d (7 days ago) • 2021-03-18 17:24:33 -0700 Engine • revision 3459eb2436 Tools • Dart 2.12.2
-
user2867907 about 3 yearsJust tried it on a real phone and the error does not show, so it seems to be a web issue only. The answer from Levi Lesches seems right.
-
Dorin Balan about 3 yearsI opened an issue too, but they were not able too reproduce it github.com/flutter/flutter/issues/79129
-
Levi Lesches almost 3 yearsI checked it out, they fixed it already on the master channel, that's why they weren't able to reproduce it.