get<T> static method
Implementation
static T? get<T>(String key) {
if (key == _tokenKeyOrNull()) {
if (_tokenCache != null) return _tokenCache as T?;
// One-time migration: a token saved by an older release still lives in
// SharedPreferences. Read it synchronously, then move it to secure
// storage and delete the plaintext copy (fire-and-forget).
final raw = _p.getString('wt_session_$key');
if (raw == null) return null;
final decoded = WtSecurity.decode(raw, WtConfig.instance.secretKey);
if (decoded == null) return null;
String? tok;
try {
tok = json.decode(decoded) as String?;
} catch (_) {
tok = decoded;
}
if (tok == null || tok.isEmpty) return null;
_tokenCache = tok;
unawaited(_secure.write(key: _kSecureToken, value: tok));
unawaited(_p.remove('wt_session_$key'));
return tok as T?;
}
final raw = _p.getString('wt_session_$key');
if (raw == null) return null;
final decoded = WtSecurity.decode(raw, WtConfig.instance.secretKey);
if (decoded == null) return null;
try {
return json.decode(decoded) as T;
} catch (_) {
return null;
}
}