Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何在Dart中获得某种类型的东西?_Flutter_Dart - Fatal编程技术网

Flutter 如何在Dart中获得某种类型的东西?

Flutter 如何在Dart中获得某种类型的东西?,flutter,dart,Flutter,Dart,下面是我正在学习的教程中的一行代码,但对于我的颤振版本,这种语法是错误的: 我使用的是颤振1.7.8,教程使用的是0.11.2,所以我想这是我的Dart版本的一个问题 final type=_typeOf(); 如何将上述代码转换为Dart的最新版本?\u typeOf不是该语言的一部分。你必须自己实现它 这相当简单: Type\u typeOf()=>T; 这应该行得通。为什么你认为它不起作用?@RémiRousselet因为VSCode抛出一个错误“没有为类定义方法”\u typeof“。

下面是我正在学习的教程中的一行代码,但对于我的颤振版本,这种语法是错误的:

我使用的是颤振1.7.8,教程使用的是0.11.2,所以我想这是我的Dart版本的一个问题

final type=_typeOf();

如何将上述代码转换为Dart的最新版本?

\u typeOf
不是该语言的一部分。你必须自己实现它

这相当简单:

Type\u typeOf()=>T;

这应该行得通。为什么你认为它不起作用?@RémiRousselet因为VSCode抛出一个错误“没有为类定义方法”\u typeof“。Dart中没有\u typeof方法(无论如何,这将是一个私有名称)。你试过运行时类型吗?你想做什么?为什么不能直接使用
BlocProvider