Reputation: 1422
I have used document.cookie to save the cookie, it works fine when I am using the browser continuously, but when I close the browser and reopen it, the cookies get removed. help me.
this is code snipit how i m using cookies.
import 'dart:html';
class CookieManager {
static addToCookie(String key, String value) {
document.cookie = "$key=$value;";
}
static String getCookie(String key) {
String cookies = document.cookie;
List<String> listValues = cookies.isNotEmpty ? cookies.split(";") : List();
String matchVal = "";
for (int i = 0; i < listValues.length; i++) {
List<String> map = listValues[i].split("=");
String _key = map[0].trim();
String _val = map[1].trim();
if (key == _key) {
matchVal = _val;
break;
}
}
return matchVal;
}
}
Upvotes: 0
Views: 2711
Reputation: 68
I guess you have to provide a timer for the cookie
void addToCookie(String key,String value){
document.cookie = "$key=$value; max-age=2592000; path=/;";}
Upvotes: 2