Dart:无法推断函数文字的类型,因为文字有一个 block 作为它的主体

标签 dart flutter

我正在使用 Flutter 开发应用。

在下面的代码中我收到了这个警告。

The type of function literal can't be inferred because the literal has a block as its body.

var onSelectSunriseNotification = () {
  print('Sunrise Notification clicked');
};

最佳答案

var 替换为 void 将删除该警告。 This issue和你的很像。

void onSelectSunriseNotification = () {
    print('Sunrise Notification clicked');
};

关于Dart:无法推断函数文字的类型,因为文字有一个 block 作为它的主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55440823/

相关文章:

json - 如何在flutter中将json格式的模型对象列表发送到API

flutter - 如何在Alert Dialog中实现搜索功能?

flutter - 如何将 ListView 添加到 Flutter 中的列?

flutter - 有什么方法可以在flf中的zefyrEditor中使用验证属性和onChanged属性?

dart - 从 JSON 中获取数据并添加到 initState() 上的列表中

dart - 如何防止 Flutter 下拉菜单发生变化?

google-maps - Flutter FutureBuilder 与 Google map 插件和自定义图标一起使用会使屏幕在启动时变黑

文本字段上的 Flutter 滚动条

flutter - 如何从扫描的照片中选择文本?

flutter - 带有 map 和信息面板的应用程序屏幕应在按钮单击或向下滑动时隐藏和显示面板