I have decoded my response.body i.e var jsonData = jsonDecode(response.body); and its working fine
But when i convert it into object and saved into local storage using sharedpref like this
if (response.statusCode == 200) {
jsonData['categoryList'].forEach((data) => {
categoryList.add(new ExpertCategory(
id: jsonData['_id'],
color: jsonData['color'],
type: jsonData['category_name'],
icon: ":)"))
});
print(categoryList) ;
localStorage.setCategoryData(categoryList.toString());
It stored in it And whenever i try to decode this its not working i.e
localStorage.getCategoryData().then((data) => {
userMap = jsonDecode(data),
});
class LocalStorage {
Future setCategoryData(data) async {
final prefs = await SharedPreferences.getInstance();
prefs.setString('category', data);
}
Future getCategoryData() async {
final prefs = await SharedPreferences.getInstance();
final category = prefs.getString('category');
return category;
}
}
import 'package:flutter/foundation.dart';
class ExpertCategory {
final String id;
final String type;
final String icon;
final String color;
const ExpertCategory( {
@required this.id,
@required this.type,
@required this.icon,
@required this.color,
});
}
its not the same as before,its showing error and after fixing some 1st element of string '[' is showing. please help with this thanks in advance.