gpt4 book ai didi

flutter - 此函数的返回类型为,但不以return语句结尾

转载 作者:行者123 更新时间:2023-12-03 04:20:07 25 4
gpt4 key购买 nike

我有警告:“此函数的返回类型为'FutureOr ',但不以return语句结尾。”
我的密码

  Future<List<Task>> getAllTasks() async {
_readTaskList().then((dynamic value) {
if (value != null) {
final List<Task> tasks = <Task>[];
final List<Task> _tasks = value as List<Task>;
tasks.forEach((dynamic element) {
_tasks.add(_convertFromJsonToTask(element as Map<String, dynamic>));
});
return tasks;
} else {
return null;
}
});
}

最佳答案

尝试执行以下操作:

Future<List<Task>> getAllTasks() async {
final dynamic value = await _readTaskList();

if (value != null) {
final List<Task> tasks = <Task>[];
final List<Task> _tasks = value as List<Task>;
tasks.forEach((dynamic element) {
_tasks.add(_convertFromJsonToTask(element as Map<String, dynamic>));
});
return tasks;
} else {
return null;
}
}
或者,如果您真的想使用 then:
Future<List<Task>> getAllTasks() {
return _readTaskList().then((dynamic value) {
if (value != null) {
final List<Task> tasks = <Task>[];
final List<Task> _tasks = value as List<Task>;
tasks.forEach((dynamic element) {
_tasks.add(_convertFromJsonToTask(element as Map<String, dynamic>));
});
return tasks;
} else {
return null;
}
});
}

关于flutter - 此函数的返回类型为,但不以return语句结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63170987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com