I am wondering if there is any way to create and read cookies in Flutter, similar to document.cookie
in Javascript. It seems logical since Flutter Web becomes Javascript when built.
CodePudding user response:
try this
import 'dart:html';
final cookie=document.cookie;
this will return string like "key=value; key2=value"
if you need the data as Map , you should use split and map method to extract the key:value form it
like:
import 'dart:html';
final cookie = document.cookie!;
final entity = cookie.split("; ").map((item) {
final split = item.split("=");
return MapEntry(split[0], split[1]);
});
final cookieMap = Map.fromEntries(entity);
for setting a cookie
document.cookie="key=value";