addCookie method
void
addCookie(})
Adds or updates a cookie in the response.
Optionally encrypts the cookie value if safe is true.
key - The name of the cookie.
value - The value of the cookie.
duration - The duration for which the cookie should be valid. Default is null.
safe - A flag indicating whether to encrypt the cookie value. Default is true.
Implementation
void addCookie(
String key,
String value, {
Duration? duration,
bool safe = true,
bool secure = false,
bool httpOnly = false,
SameSite? sameSite,
String path = '/',
DateTime? expires,
String? domain,
}) {
key = fixCookieName(key);
removeCookie(key);
value = safe ? value.toSafe(FinchApp.config.cookiePassword) : value;
var cookie = Cookie(key, value);
cookie.maxAge = duration?.inSeconds;
cookie.path = path;
cookie.secure = secure;
cookie.httpOnly = httpOnly;
cookie.sameSite = sameSite;
cookie.expires = expires;
cookie.domain = domain;
_rq.response.cookies.add(cookie);
_rq.cookies.add(cookie);
}