最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

问题连接扑应用API服务器

IT培训 admin 4浏览 0评论

问题连接扑应用API服务器

任何一个可以支持我..我累了连接到我的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(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)

,,任何意见

My API server

回答如下:

更改这样的方法的返回类型:

Future<Map<String, dynamic>> getData() async {
    ...
}

问题连接扑应用API服务器

任何一个可以支持我..我累了连接到我的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(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)

,,任何意见

My API server

回答如下:

更改这样的方法的返回类型:

Future<Map<String, dynamic>> getData() async {
    ...
}

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论