SweetCookieJar class abstract

This class represents a jar that manages cookies.

For the constructor of this class, specify the Response returned when HTTP communication is performed. When the constructor is executed, the cookie information is safely extracted from the header information of Response passed to the constructor.

After the constructor process is completed and an instance of this SweetCookieJar is created, use the isEmpty or isNotEmpty method to check whether the extracted cookie information exists or not.

This class provides useful functions for managing cookies. For example, you can use the find method or findAll method to fetch the cookies you want.

The find method finds for and returns the cookie linked to the name specified in the argument The findAll method finds for and returns the all cookies linked to the name specified in the argument.

Example:*

import 'package:http/http.dart';
import 'package:sweet_cookie_jar/sweet_cookie_jar.dart';

void main() {
  final cookieJar = SweetCookieJar.from(response: response);

  if (cookieJar.isEmpty) {
    // It means that there is no cookie information
    // in the response header.
    return;
  }

  final cookie = cookieJar.find(name: 'AWSALB');
  print(cookie.name);
  print(cookie.value);
  print(cookie.toJson());

  if (cookie.isExpired) {
    // Do something
    return;
  }
}

Constructors

SweetCookieJar.from({required Response response})
Returns the new instance of SweetCookieJar based on an argument.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Returns true if this cookie jar is empty, otherwise false.
no setter
isNotEmpty bool
Returns true if this cookie jar is not empty, otherwise false.
no setter
nameSet Set<String>
Returns the set of cookie names.
no setter
rawData String
Returns raw set cookie data.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

containsName({required String name}) bool
Returns true if this cookie jar contains cookie linked to name, otherwise false.
find({required String name}) Cookie
Returns the cookie linked to name, otherwise empty cookie.
findAll({required String name}) List<Cookie>
Returns all cookies linked to name, otherwise empty list.
findAllValues({required String name}) List<String>
Returns all cookie values linked to name, otherwise empty list.
findValue({required String name}) String
Returns the cookie value linked to name, otherwise empty string.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator +(SweetCookieJar cookieJar) SweetCookieJar
Combines two SweetCookieJars.
operator ==(Object other) bool
The equality operator.
inherited