Flutter 颤振:此函数的返回类型为';未来<;动态>';,但是';t以return语句结束
我试图使用一个列表(自定义类型),但出现错误。 在这两条线上。List和getData在VSCode中显示类似红色的错误Flutter 颤振:此函数的返回类型为';未来<;动态>';,但是';t以return语句结束,flutter,Flutter,我试图使用一个列表(自定义类型),但出现错误。 在这两条线上。List和getData在VSCode中显示类似红色的错误 Future List<UserVideo> getData() async { List<UserVideo> list = []; 编辑 Name non-constant identifiers using lowerCamelCase.dartnon_constant_identifier_names This function
Future List<UserVideo> getData() async {
List<UserVideo> list = [];
编辑
Name non-constant identifiers using lowerCamelCase.dartnon_constant_identifier_names
This function has a return type of 'Future<dynamic>', but doesn't end with a return statement.
Try adding a return statement, or changing the return type to 'void'.dartmissing_return
Functions must have an explicit list of parameters.
Try adding a parameter list.dart(missing_function_parameters)
JayDev帮助我解决了这个错误,但现在它又给了我另一个错误
当我尝试使用getData()函数时。如下图所示
List<UserVideo> videoDataList = [];
videoDataList = UserVideo.getData();
List videoDataList=[];
videoDataList=UserVideo.getData();
我得到了错误
A value of type 'Future<List<UserVideo>>' can't be assigned to a variable of type 'List<UserVideo>'.
Try changing the type of the variable, or casting the right-hand type to 'List<UserVideo>'.
无法将“Future”类型的值分配给“List”类型的变量。
尝试更改变量的类型,或将右侧类型强制转换为“List”。
我认为您的方法签名是错误的。您应该将希望从未来返回的类型放在后面的大括号中,即
Future getData()异步{
...
}
我认为您的方法签名是错误的。您应该将希望从未来返回的类型放在后面的大括号中,即
Future getData()异步{
...
}
啊,我的错。:)让我试试。投票通过。当我使用这个函数时,我得到了错误。“Future”类型的值无法分配给“List”类型的变量。尝试更改变量的类型,或将右侧类型强制转换为“List”。啊,我的错。:)让我试试。投票通过。当我使用这个函数时,我得到了错误。“Future”类型的值无法分配给“List”类型的变量。尝试更改变量的类型,或将右侧类型强制转换为“List”。
A function body must be provided.
Try adding a function body.
List<UserVideo> videoDataList = [];
videoDataList = UserVideo.getData();
A value of type 'Future<List<UserVideo>>' can't be assigned to a variable of type 'List<UserVideo>'.
Try changing the type of the variable, or casting the right-hand type to 'List<UserVideo>'.