【问题标题】:Problem with connect Flutter App API server连接 Flutter App API 服务器的问题
【发布时间】:2019-06-27 14:32:16
【问题描述】:

任何人都可以支持我 .. 我厌倦了连接到我的 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)

,, 任何建议

My API server

【问题讨论】:

    标签: node.js api flutter


    【解决方案1】:

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

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

    【讨论】:

    • 我只是将对象放在列表中,然后它工作正常......谢谢
    猜你喜欢
    • 1970-01-01
    • 2017-05-06
    • 2023-03-06
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    相关资源
    最近更新 更多