Dart: html < /h4>
dart: html. Вместо этого используйте DART: JS_INTEROP и
падж :ВЕБ.И.
Код: Выделить всё
import 'package:universal_html/html.dart' as html;
class CookieManager {
static void addToCookie(String key, dynamic value) {
// 2592000 sec = 30 days.
// 1296000 sec = 15 days.
int sevenDays = 604800; // 7 days.
//int oneDay = 86400; // 1 day.
html.document.cookie = "$key=$value; max-age=$sevenDays; path=/;";
}
static bool? getCookieBool(String key) {
String? cookieValue = getCookie(key); // Get the cookie value as a string
if (cookieValue == null) {
return null; // Handle the case where the cookie is not set
}
// Convert the string to a boolean (case-insensitive)
if (cookieValue.toLowerCase() == 'true') {
return true;
} else if (cookieValue.toLowerCase() == 'false') {
return false;
} else {
return null; // Or handle invalid cookie values as you see fit.
}
}
static dynamic getCookie(String key) {
dynamic cookies = html.document.cookie;
if (cookies == null || cookies.isEmpty) {
return null;
}
List cookieList = cookies.split(';');
for (dynamic cookie in cookieList) {
List parts = cookie.trim().split('=');
if (parts.length == 2 && parts[0] == key) {
return parts[1];
}
}
return null;
}
static void removeCookie(String key) {
html.document.cookie = '$key=; Max-Age=0; path=/';
}
static bool isCookiePresent(String key) {
String? cookieValue = getCookie(key); // Get the cookie value as a string
if (cookieValue == null) {
return false; // Cookie is not present
} else {
return true; // Cookie is present
}
}
}
Я знаю, что это работает в режиме debug:
Тем не менее, он не работает в производстве. Эта проблема является потомком проблемы, о которой я ранее спрашивал и решал в этой теме (к сожалению, теперь у него есть 1 голос, чтобы закрыть тему вопроса). < /P>
Вот мои основные вопросы: < /p>
- Как решить эту проблему? /> Есть ли другой способ обработки файлов cookie с использованием импорта 'dart: js_interop' или другая связанная библиотека?
Подробнее здесь: https://stackoverflow.com/questions/796 ... s-in-debug
Мобильная версия