getCookies method

Future<List<Cookie>> getCookies(
  1. String url
)

Retrieves cookies for a specific request URL.

This method loads all cookies that match the given url from the current _cookieJar. These cookies are the ones that would be sent automatically with a request to this URL.

Parameters:

  • url: The target endpoint used to filter relevant cookies.

Returns:

  • A list of Cookie objects associated with the provided URL.

Notes:

  • This does not trigger a network request.
  • Useful for debugging or manually inspecting session state.
  • Works only on non-web platforms when using Dio with CookieJar.

Example:

final cookies = await getCookies("https://example.com");
for (final cookie in cookies) {
  print("${cookie.name}: ${cookie.value}");
}

Implementation

Future<List<Cookie>> getCookies(String url) async {
  return await _cookieJar?.loadForRequest(Uri.parse(url)) ?? [];
}