Home > Software engineering >  Flutter access session as Json array
Flutter access session as Json array

Time:07-16

i have added a json array in session. when i try to access the array, it shows as string. that is without any double quotes. but i want it as json array. Am i missing anything here ? please help. this is the array :

var login_data = {"success":1, "user":{"id":"13","firstname":"Reda","lastname":"Estyu"},"shop_name" :"Market"}
await FlutterSession().set('session_data', login_data);
var get_data = await FlutterSession().get("session_data");
print(get_data); 

after accessing it from session it looks like this : {success:1, user:{id:13,firstname:Reda,lastname:Estyu},shop_name :Market}

CodePudding user response:

Setting Map returns Map and setting String returns String - makes sense. Encode Map to String before setting.

await FlutterSession().set('session_data', jsonEncode(login_data));
...
var get_data = jsonDecode(await FlutterSession().get("session_data"));
  • Related