- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我使用 flutter http 包创建了简单的发布请求。但是我在发送请求时遇到了以下错误。
E/flutter ( 9479): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter ( 9479): type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, String>'
E/flutter ( 9479): #0 ApiRequester.sendLoginRequest (package:fitness_lanka/api_requester.dart:56:16)
E/flutter ( 9479): <asynchronous suspension>
E/flutter ( 9479): #1 LoginWidgets.buildLoginButton.<anonymous closure> (package:fitness_lanka/widgets/login_widgets.dart:82:62)
E/flutter ( 9479): #2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
E/flutter ( 9479): #3 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
E/flutter ( 9479): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter ( 9479): #5 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
E/flutter ( 9479): #6 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
E/flutter ( 9479): #7 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
E/flutter ( 9479): #8 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
E/flutter ( 9479): #9 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
E/flutter ( 9479): #10 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
E/flutter ( 9479): #11 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
E/flutter ( 9479): #12 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
E/flutter ( 9479): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
E/flutter ( 9479): #14 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
E/flutter ( 9479): #15 _invoke1 (dart:ui/hooks.dart:153:13)
E/flutter ( 9479): #16 _dispatchPointerDataPacket (dart:ui/hooks.dart:107:5)
下面是我用来发送post请求的函数。
static Future<LoginData> sendLoginRequest(
String email, String password) async {
var headers = {'Accept': 'application/json'};
var body = {
'email': email,
'password': password,
};
http.Response response = await http.post(
"https://fitness-lanka-laravel.herokuapp.com/api/user/login",
headers: headers,
body: body,
);
return LoginData.fromResponse(response);
}
我将 flutter 从 v0.8.2 升级到了 v0.9.4。在将 flutter 升级到最新版本之前,它运行良好。
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.9.4, on Microsoft Windows [Version 10.0.17134.345], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.2)
[√] Android Studio (version 3.2)
[√] IntelliJ IDEA Community Edition (version 2018.2)
[√] VS Code (version 1.28.1)
[√] Connected devices (1 available)
• No issues found!
-----更新-----
我将 flutter 降级到 v0.8.2。现在我遇到了不同的错误。
E/flutter (24516): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter (24516): NoSuchMethodError: The getter 'length' was called on null.
E/flutter (24516): Receiver: null
E/flutter (24516): Tried calling: length
E/flutter (24516): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:48:5)
E/flutter (24516): #1 _Uri._uriEncode (dart:core/runtime/liburi_patch.dart:44:23)
E/flutter (24516): #2 Uri.encodeQueryComponent (dart:core/uri.dart:1092:17)
E/flutter (24516): #3 mapToQuery.<anonymous closure> (package:http/src/utils.dart:19:22)
E/flutter (24516): #4 CastMap.forEach.<anonymous closure> (dart:_internal/cast.dart:286:8)
E/flutter (24516): #5 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.forEach (dart:collection/runtime/libcompact_hash.dart:365:8)
E/flutter (24516): #6 CastMap.forEach (dart:_internal/cast.dart:285:13)
E/flutter (24516): #7 mapToQuery (package:http/src/utils.dart:17:7)
E/flutter (24516): #8 Request.bodyFields= (package:http/src/request.dart:128:17)
E/flutter (24516): #9 BaseClient._sendUnstreamed (package:http/src/base_client.dart:165:17)
E/flutter (24516): <asynchronous suspension>
E/flutter (24516): #10 BaseClient.post (package:http/src/base_client.dart:56:5)
E/flutter (24516): #11 post.<anonymous closure> (package:http/http.dart:70:34)
E/flutter (24516): #12 _withClient (package:http/http.dart:167:20)
E/flutter (24516): <asynchronous suspension>
E/flutter (24516): #13 post (package:http/http.dart:70:3)
E/flutter (24516): #14 ApiRequester.sendLoginRequest (package:fitness_lanka/api_requester.dart:55:36)
E/flutter (24516): <asynchronous suspension>
E/flutter (24516): #15 LoginWidgets.buildLoginButton.<anonymous closure> (package:fitness_lanka/widgets/login_widgets.dart:84:62)
E/flutter (24516): #16 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:503:14)
E/flutter (24516): #17 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:558:30)
E/flutter (24516): #18 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter (24516): #19 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
E/flutter (24516): #20 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
E/flutter (24516): #21 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
E/flutter (24516): #22 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
E/flutter (24516): #23 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
E/flutter (24516): #24 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
E/flutter (24516): #25 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
E/flutter (24516): #26 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
E/flutter (24516): #27 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
E/flutter (24516): #28 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
E/flutter (24516): #29 _invoke1 (dart:ui/hooks.dart:142:13)
E/flutter (24516): #30 _dispatchPointerDataPacket (dart:ui/hooks.dart:99:5)
最佳答案
以下代码对我有用:)
static Future<LoginData> sendLoginRequest(
String email, String password) async {
// Encode the string [uri] using percent-encoding to make it
// safe for literal use as a full URI.
String url = Uri.encodeFull('https://fitness-lanka-laravel.herokuapp.com/api/user/login');
// headers should be a subtype of Map<String, String>
Map<String, String> headers = {
"Accept": "application/json",
"Content-Type": "application/json",
};
// convert body to a JSON string
String body = json.encode(
{
'email': email,
'password': password,
},
);
// now it's safe to send the request
http.Response response = await http.post(
url,
body: body,
headers: headers,
);
return LoginData.fromResponse(response);
}
如果有人在 json.encode(body)
遇到错误
请添加导入:import 'dart:convert';
关于dart - Flutter http 错误类型 '_InternalLinkedHashMap<dynamic, dynamic>' 不是类型 'Map<String, String>' 的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52879304/
在创建两个类来创建这个 json 结构之后: { "data": [ { "staff_id": "1111", "class_id": "222222",
有时,在 Dart 中遍历复杂的 json 文件时,如果我们能告诉我们的编辑器预期的结构是什么,以便我们可以充分利用编辑器的智能代码完成功能,那就太好了。 作为一个玩具示例,请考虑脚本 writer.
在存储到本地数据库之前将json字符串转换为对象的正确方法是什么? 这是i['created_by_user']的输出: {id: 3, name: A} 我试图将其转换为CreatedBy对象 C
我已将Cloud Firestore设置为数据库,并正在使用 map 检索文档,这是快照: 当我尝试使用get()检索文档时,我得到了DocumentSnapshot,然后将其转换为Map,其中包括许
Sthg 让我发疯,我尝试在卡片中显示 json 产品,但它不起作用。到目前为止,这是我尝试过的: 产品类别: class Product { final String id; Produ
我正在调用一个 post API,我必须在其中发送 FormData 但在收到响应后,当我尝试解析该响应时,我遇到了异常。 static Future versionApiRequest(String
Dart / Flutter的新功能。我创建了一个gridview,然后在网格中点击一个项目后,我想将JSON数据传递到下一页。但是,我收到一个错误,我认为这与无法正确进行类型转换有关。我希望下一页显
尝试解析JSON并将其显示在文本中而不是listview时出现错误。 以下是我的JSON结构。 { "status": "success", "data": { "id
我对Flutter很陌生,想呈现一个ListView。但是我得到一个错误。 我有3个模型类: 主题,主题和内容。 这是模型文件topic.dart: import './content.dart';
抱歉,我现在正在编程中,但是我正在学习中,请帮助我。我被困在这个问题上。这是我的第一个应用程序,在likke帮助下需要完成所有工作。 我收到此错误:类型'_InternalLinkedHashMap'
我正在尝试使用网络调用实现一个简单的新闻提要应用程序,其中屏幕将在 ListView 中显示最新的故事。 使用当前代码,我从 API 获得了响应(因为我在日志中看到了整个响应主体),但似乎无法在 UI
这是我的问题。在屏幕中,我使用的是 Navigator.pushnamed()...带有参数以将信息发送到具有详细 View 的屏幕。它工作正常!这是代码:Navigator.pushNamed(co
嗨,我是 Flutter 的新手,遇到了问题。 我想将从 Firestore 获取的数据添加到 List 类型的变量中,但出现错误。我花了几个小时来解决这个问题,但效果不佳。 有人知道我是如何得到这个
我收到以下错误: The following _TypeError was thrown building FutureBuilder(dirty, state: _FutureBuilderStat
这是我的错误行: 这是我的代码: 最佳答案 final jobs= json.decode(response.body)['name_database_table']; 关于mobile - NoSu
点击登录按钮后出现错误->未处理的异常:类型“_InternalLinkedHashMap”不是类型“String”的子类型 } 捕获(e){扔 e;//这里}请帮助我,我不明白如何解决 未处理的异常
我正在尝试解析 json,将其打印到控制台,然后放入 ListView.builder 并收到此错误:type '_InternalLinkedHashMap' is not a subtype of
背景 我正在开发一个可帮助小学老师的应用程序。 该应用程序允许用户从字母表中选择字母,当他们继续进入下一个屏幕时,他们选择的字母应显示为可翻转卡片。一侧有字母,另一侧有图像。 这些卡应占据整个屏幕,并
这是回应 { "overview": "A ticking-time-bomb insomniac and a slippery soap salesman channel primal male a
我有一个JSON如下 { "status": 1, "msg": "Success", "data": { "lastIndex": 50, "
我是一名优秀的程序员,十分优秀!