Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type '_OneByteString' is not a subtype of type 'Map<String, dynamic>' #883

Closed
easazade opened this issue Aug 4, 2020 · 34 comments
Closed

Comments

@easazade
Copy link

easazade commented Aug 4, 2020

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 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));

additional info :
platform i test on : android
platform version : 8.0
dio version : 3.0.9
report rate : 5 % of the time only in release mode

@stale
Copy link

stale bot commented Sep 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Sep 4, 2020
@easazade
Copy link
Author

easazade commented Sep 4, 2020

this is still an issue.

@stale stale bot removed the stale label Sep 4, 2020
@RalphNoel
Copy link

In Release mode, the app is working fine, but after few hours i got this same issue, for me also but if i clear the cache its working perfectly...

@easazade
Copy link
Author

easazade commented Sep 5, 2020

by clearing cache you mean the application cache?

@RalphNoel
Copy link

Yeah @easazade

@easazade
Copy link
Author

easazade commented Sep 5, 2020

i guess it could be a cache problem since whenever i quit app and launch it again. everything works fine.

@RalphNoel
Copy link

Actually, What's the solution for this issue to overcome @easazade

@stale
Copy link

stale bot commented Oct 10, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Oct 10, 2020
@stale stale bot closed this as completed Oct 17, 2020
@zeuscode
Copy link

zeuscode commented Apr 8, 2021

this is issue is still, i. meet.

@Maged12
Copy link

Maged12 commented Jul 16, 2021

I have the same problem too and it is in shared preferences when I use this line
bool isFirstTime = Global.prefs?.getBool('isFirstTime') ?? "true";
And the error is
type '_OneByteString' is not a subtype of type 'bool'
Any solution ?

@iamsannyrai
Copy link

@Maged12 you are passing string value in bool type when a value from your shared preference is null.

Should be following..

bool isFirstTime = Global.prefs?.getBool('isFirstTime') ?? true;

@fanchou
Copy link

fanchou commented Sep 9, 2021

+1

@StitchC
Copy link

StitchC commented Jan 8, 2022

+1
my issue is info: type '_TwoByteString' is not a subtype of type 'bool'
what a serious!

@oleksandrm1608
Copy link

hey, any solution for that ?? it's still an issue for me

@mouryaavadhesh
Copy link

hey, any solution for that ?? it's still an issue for me
| exception: type '_OneByteString' is not a subtype of type 'Map<String, dynamic>' | [device_info: OPPO_CPH2127_53a2372f1831d9ec_qcom]

@a475893401
Copy link

type '_OneByteString' is not a subtype of type 'int' of 'index'

@subzero911
Copy link

I have the similar issue
type '_TwoByteString' is not a subtype of type 'Map<String, dynamic>'. Error thrown null.
image

@matiazar
Copy link

I have the same problem. On one device, with released app.

@dimas-ibnu
Copy link

how can i fix it ? its still appear on my crashlytics

@Asquare17
Copy link

this is still an issue.

@easazade how did you resolve this?
It happens only in release mode and to less than 5% of users.

@easazade
Copy link
Author

easazade commented Sep 8, 2022

@Asquare17 I didn't. it just didn't happen for me when i built the app apk. it just happened sometimes when i ran app in release mode directly on device

@PawanFyers
Copy link

We have seen the same issue on Crashlytics console:
io.flutter.plugins.firebase.crashlytics.FlutterError: Exception type '_OneByteString' is not a subtype of type 'int'

@FDuhen
Copy link

FDuhen commented Oct 24, 2022

+1, only happens in Release mode

@MeherBa
Copy link

MeherBa commented Nov 14, 2022

how to fix it ? its still appear on my crashlytics console

@maxzod
Copy link

maxzod commented Nov 21, 2022

still appearing on sentry.io console

@Mashood97
Copy link

It's still appearing in release mode any solution for this ??

@IguJl15
Copy link

IguJl15 commented Nov 24, 2022

I am getting the same error when trying to parse a value from api to bool. But I realized that the api I am using is sending boolean in text ("true" instead of the true boolean true). In our case, this occurs as a safety measure against null values. We created a CustomBoolean enum that has a not_selected value to prevent null values from being returned from the api:

enum CustomBoolean {
  TRUE,
  FALSE,
  NOT_SELECTED;
}

If it is your case I've solved this creating a simple parser:

  static CustomBoolean parse(String source) {
    source
      ..replaceAll(" ", "_")
      ..toUpperCase()
      ..trim();

    switch (source) {
      case "TRUE":
        return CustomBoolean.TRUE;
      case "FALSE":
        return CustomBoolean.FALSE;
      default:
        return CustomBoolean.NOT_SELECTED;
    }
  }

By doing this we are converting the string from the api to a enum value. To get a bool value you can change the enumeration values on switch statement to booleans has well, in my case I prefered setting values on the enum:

enum CustomBoolean {
  TRUE(true),
  FALSE(false),
  NOT_SELECTED(false);

  final bool value;

  const CustomBoolean(this.value);

  static CustomBoolean parse(String source) {
    source
      ..replaceAll(" ", "_")
      ..toUpperCase()
      ..trim();

    switch (source) {
      case "TRUE":
        return CustomBoolean.TRUE;
      case "FALSE":
        return CustomBoolean.FALSE;
      default:
        return CustomBoolean.NOT_SELECTED;
    }
  }
}

Remembering that this is a solution for boolean values where I use enum, but you can use the parse as a standalone function returning boolan value directly.

@nullskill
Copy link

nullskill commented Dec 11, 2022

I got similar issue saying type '_OneByteString' is not a subtype of type 'Value<String?>' while using http and drift packages.
It's related to type casting. My case was getting a Map<String, dynamic> structure from a Rest API and eventually trying to insert the value from it into SQLite table using Drift API like this:

final accessToken = authResult['access_token'];
UserCompanion.insert(
  id: Value(user.id),
  authCode: code,
  accessToken: accessToken,
);

So the type of the accessToken was dynamic and I got such weird issue. Finally I modified the code like this and it's gone:

final accessToken = authResult['access_token'] as String;
UserCompanion.insert(
  id: Value(user.id),
  authCode: code,
  accessToken: Value(accessToken),
);

@WiRight
Copy link

WiRight commented Dec 26, 2022

Check your StackTrace. The first 10 lines will be enough.

Cover your runApp with runZonedGuarded or try/catch with getting StackTrace/StackTrace.current and in 90% it will be some Map with wrong key data

@ousvat
Copy link

ousvat commented Mar 23, 2023

Which is the solution?

I also have this issue: FlutterError: type '_OneByteString' is not a subtype of type 'Map<String, dynamic>' in type cast

@mouryaavadhesh
Copy link

Any solution for this?

@AlexV525
Copy link
Member

This should be fixed already in cce167e.

@IguJl15
Copy link

IguJl15 commented Mar 23, 2023

@mouryaavadhesh @ousvat

Can you paste here the StackTrace and the code where the error occurs? So then we can suggest something. But, just as @WiRight pointed above, most of the time this error occurs when accessing a key that exists in a map but with wrong type than what you expect.

In my case, API was returning a string "true" instead of the boolean value true or false. And i was tring to pass the jsonFromApi["boolValue"] directly to a boolean parameter.

To solve this, i made a simple parser to read the string and pass it to boolean.

Details

static bool? tryParseBoolean(String source) {
    source
      ..toUpperCase()
      ..trim();

    switch (source) {
      case "TRUE":
        return true;
      case "FALSE":
        return false;
      default:
        return null;
    }
  }

@zakaria02
Copy link

A value of type '_OneByteString' can't be assigned to a variable of type 'String?'. any solution for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests