getAllCookies method Null safety

Future<List<Cookie>> getAllCookies()

Fetches all stored cookies.

NOTE: available on iOS 11.0+.

Official iOS API: https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882005-getallcookies

Implementation

Future<List<Cookie>> getAllCookies() async {
  List<Cookie> cookies = [];

  Map<String, dynamic> args = <String, dynamic>{};
  List<dynamic> cookieListMap =
      await CookieManager._channel.invokeMethod('getAllCookies', args);
  cookieListMap = cookieListMap.cast<Map<dynamic, dynamic>>();

  cookieListMap.forEach((cookieMap) {
    cookies.add(Cookie(
        name: cookieMap["name"],
        value: cookieMap["value"],
        expiresDate: cookieMap["expiresDate"],
        isSessionOnly: cookieMap["isSessionOnly"],
        domain: cookieMap["domain"],
        sameSite: HTTPCookieSameSitePolicy.fromValue(cookieMap["sameSite"]),
        isSecure: cookieMap["isSecure"],
        isHttpOnly: cookieMap["isHttpOnly"],
        path: cookieMap["path"]));
  });
  return cookies;
}