getItem method

String? getItem({
  1. CStorageMethod method = CStorageMethod.local,
  2. required String key,
})

Gets data from the identified CStorageMethod via the specified key.

Implementation

String? getItem({
  CStorageMethod method = CStorageMethod.local,
  required String key,
}) {
  if (method == CStorageMethod.local) {
    return web.window.localStorage.getItem(key);
  } else if (method == CStorageMethod.session) {
    return web.window.sessionStorage.getItem(key);
  } else {
    var name = "$key=";
    var ca = web.document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
      var c = ca[i];
      while (c[0] == " ") {
        c = c.substring(1);
      }
      if (c.indexOf(name) == 0) {
        return c.substring(name.length, c.length);
      }
    }
    return null;
  }
}