我试图弄清楚如何在这样的代码中指定类型:
import 'dart:convert';
import 'package:http/http.dart' as http;
main() async {
Map repos = await(fetchJson());
print(repos['name']);
}
Object fetchJson() async {
final uri = 'https://api.github.com/users/sjindel-google/repos';
final response = await http.get(uri);
return jsonDecode(response.body)[1];
}
该代码有效,但是我想指定fetchJson()的类型。似乎应该是:
Future<Map> fetchJson() async {
但这给了我运行时错误:
Error: 'Future' expects 0 type arguments.
什么是正确的方法?