任何人都可以支持我..我厌倦了连接到我的API,但是我遇到了错误, 我的代码
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<List> getData() async {
String url = 'http://localhost:4000/api/contacts';
http.Response response = await http.get(url);
return json.decode(response.body);
}
void main() async {
List data = await (getData());
print(data);
}
但是我出错了
Performing hot restart...
Syncing files to device Android SDK built for x86...
Restarted application in 7,213ms.
E/flutter ( 5291): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter ( 5291): type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'FutureOr<List<dynamic>>'
E/flutter ( 5291): #0 getData (package:json/main.dart:13:3)
E/flutter ( 5291): <asynchronous suspension>
E/flutter ( 5291): #1 main (package:json/main.dart:17:22)
E/flutter ( 5291): <asynchronous suspension>
E/flutter ( 5291): #2 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:289:19)
E/flutter ( 5291): #3 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
,任何建议
答案 0 :(得分:0)
像这样更改方法的返回类型:
/test