removeCookie method

void removeCookie(
  1. String key, {
  2. String path = '/',
})

Removes a cookie by setting its value to an empty string and expiration to a past date.

key - The name of the cookie to be removed.

Implementation

void removeCookie(String key, {String path = '/'}) {
  key = fixCookieName(key);
  _rq.cookies.removeWhere((element) => element.name == key);
  _rq.response.cookies.removeWhere((element) => element.name == key);

  // Add expired cookie to tell browser to remove it
  var cookie = Cookie(key, '');
  cookie.maxAge = 0;
  cookie.expires = DateTime.now().subtract(const Duration(days: 1));
  cookie.path = path;
  _rq.response.cookies.add(cookie);
}