flutter有一些报错如下

flutter报错The type of the function literal can't be inferred because the literal has a block as its body.A value of type 'String?' can't be assigned to a variable of type '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 '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'.

flutter报错The type of the function literal can't be inferred because the literal has a block as its body.A value of type 'String?' can't be assigned to a variable of type '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;

相关文章:

  • 2021-09-11
  • 2021-10-25
  • 2021-11-17
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
相关资源
相似解决方案