type '_OneByteString' is not a subtype of type 'Map<String, dynamic>'
Asked Answered
C

1

5

This is an error I get only in release mode (weird) when I'm trying to parse response body of a network request i made into a json map. I put down the code and also the error stacktrace below. the other wierd thing i should mention is that it only happens sometimes. not all the time. but for the apps i have released on the market when i check the crash reports on firebase this error is also reported there. (it does not cause a crash, though)

i should mention i use Dio package as http client

update : I found out that it happens sometimes but when it happens it keeps happening when i send the same request or sometimes other request over and over. until i quit the app and run it again.

Error stacktrace :

I/flutter (31714): type '_OneByteString' is not a subtype of type 'Map<String, dynamic>'
I/flutter (31714): #0      Server.getUser (package:mehrgan/data/network/server.dart:83)
I/flutter (31714): <asynchronous suspension>
I/flutter (31714): #1      Future.wait.<anonymous closure> (dart:async/future.dart:0)
I/flutter (31714): <asynchronous suspension>
I/flutter (31714): type '_OneByteString' is not a subtype of type 'Map<String, dynamic>'
I/flutter (31714): #0      Server.getCourses (package:mehrgan/data/network/server.dart:101)
I/flutter (31714): <asynchronous suspension>
I/flutter (31714): #1      Future.wait.<anonymous closure> (dart:async/future.dart:0)
I/flutter (31714): <asynchronous suspension>

my code :

Response response = await _dio.get('user/info');
Map<String, dynamic> json = jsonDecode(jsonEncode(response.data));
Coppock answered 4/8, 2020 at 8:5 Comment(3)
Have you find the solution bro? It happen to me too but only in release mode. Using dio package too. Its very2 weird.Recumbent
@ThiyraashDavid no man. i even opened a github issue. and it has been tagged stale you can check it out github.com/flutterchina/dio/issues/883Coppock
Mine been fixed bro. I didn't do anything on my side. The server side return wrong format of data. Maybe check your production return data of the particular pageRecumbent
L
6

I encountered this problem using Dart/Flutter with the Dio client library.

Server side I was requesting data from a PHP script.

I fixed the issue by putting in the following line in my PHP script:

header('Content-Type: application/json');

Huge thanks to Thiyraash David above who gave me the clue I needed to solve my issue.

Libido answered 13/11, 2020 at 22:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.