flutterflutter-web

How to add expires to flutter web cookie?


I am using document.cookie to store cookie in my web app. i want to add 'expires' parameter and set expire after 30 days. how can i do this.

  void _addToCookie(String key, String value) {
    document.cookie = "$key=$value;expires=30";
  }

Solution

  • use "max-age" parameter instead of "expires". "max-age" requires seconds ;max-age=max-age-in-seconds (e.g., 606024*365 or 31536000 for a year)

    for 30 days 30×24×60×60 = 2592000.

     void addToCookie(String key, String value) {
        document.cookie = "$key=$value; max-age=2592000;";
      }