Flutter 'showDatePicker' throws exception: Error: Expected a value of type 'String', but got one of type 'Null'

Flutter 'showDatePicker' throws exception: Error: Expected a value of type 'String', but got one of type 'Null'

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));
}

DatePicker 弹出,但是当您尝试 select 一个日期或年份时,它会抛出: Expected a value of type 'String', but got one of type [=16] =]

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

我在使用最新的 flutter for web 时看到了同样的情况。看起来错误出在日期选择器本身,而不是我的代码中?尽管调试控制台中显示错误消息,但日期选择器似乎仍能按预期运行?

编辑:这已在主频道中修复并将很快发布

我为此提交了一个错误:https://github.com/flutter/flutter/issues/79834

这是由于当您点击弹出窗口 window 中的几乎所有内容时,框架会在内部调用 HapticFeedback.vibrate() 以发出有趣的小嗡嗡声。但是,在 Web 上,这不起作用。有一个 switch-case 尝试查看平台是否支持它,但是 Web 一直没有合适的TargetPlatform,所以代码认为计算机可以振动。

当 Flutter 尝试向 Web 引擎发送消息时,发生空错误。

我用的是2.2.3稳定版,这个问题已经解决了