flutter报错The type of the function literal can't be inferred because the literal has a block as

2021/9/12 6:06:26

本文主要是介绍flutter报错The type of the function literal can't be inferred because the literal has a block as,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

flutter有一些报错如下

在这里插入图片描述
The type of the function literal can't be inferred because the literal has a block as its body.
Try adding an explicit type to the variable.dart(top_level_function_literal_block)
A value of type 'String?' can't be assigned to a variable of type 'String'.
Try changing the type of the variable, or casting the right-hand type to 'String'.

在这里插入图片描述

The type of the function literal can't be inferred because the literal has a block as its body.
Try adding an explicit type to the variable.dart(top_level_function_literal_block)
A value of type 'StatefulWidget Function(dynamic)?' can't be assigned to a variable of type 'Function'.
Try changing the type of the variable, or casting the right-hand type to 'Function'.

The type of the function literal can't be inferred because the literal has a block as its body.
Try adding an explicit type to the variable.

解决方案

// final String name = settings.name;
final String? name = settings.name;
// final Function pageContentBuilder = routes[name];
final Function pageContentBuilder = routes[name] as Function;


这篇关于flutter报错The type of the function literal can't be inferred because the literal has a block as的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程