Getting the format exception while passing the token with '|' inside jsonDecode().
final SharedPreferences pref = await SharedPreferences.getInstance();
value = pref.get("token") as String;
if (value?.isEmpty ?? true) {
return null;
} else {
final Map<String, dynamic> map = await _parseJson(value);
return OldToken.fromJson(map);
}
static Future<Map<String, dynamic>> _parseJson(String text) {
return compute(_parseAndDecode, text);
}
static Map<String, dynamic> _parseAndDecode(String response) {
return jsonDecode(response) as Map<String, dynamic>;
}
When you use SharedPreferences you retrieve directly a String, so you don't need to decode a json value.