pretty_cookie.dart 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import 'package:cookie_jar/cookie_jar.dart';
  2. class CookieJarImpl implements CookieJar {
  3. static const String _COOKIE_KEY_AUTH = 'ky_auth';
  4. static const String _COOKIE_KEY_SDK = 'sdk';
  5. static const String _COOKIE_AUTH_SAVE_KEY = 'KeyAuthCookie';
  6. void saveCookieValue(String value) {
  7. //save cookie into sp
  8. }
  9. String getCookieValue() {
  10. //get cookie from sp
  11. return "";
  12. }
  13. @override
  14. bool get ignoreExpires => false;
  15. @override
  16. Future<void> delete(Uri uri, [bool withDomainSharedCookie = false]) {
  17. // TODO: implement delete
  18. throw UnimplementedError();
  19. }
  20. @override
  21. Future<void> deleteAll() {
  22. // TODO: implement deleteAll
  23. throw UnimplementedError();
  24. }
  25. @override
  26. Future<List<Cookie>> loadForRequest(Uri uri) {
  27. List<Cookie> cookies = [];
  28. var cookie1 = Cookie(_COOKIE_KEY_SDK, '28')..domain = uri.host;
  29. cookies.add(cookie1);
  30. var cookie2 = Cookie(_COOKIE_KEY_AUTH, getCookieValue())..domain = uri.host;
  31. cookies.add(cookie2);
  32. return Future.value(cookies);
  33. }
  34. @override
  35. Future<void> saveFromResponse(Uri uri, List<Cookie> cookies) {
  36. Cookie cookieValue =
  37. cookies.singleWhere((element) => element.name == _COOKIE_KEY_AUTH);
  38. if (cookieValue != null) {
  39. saveCookieValue(cookieValue.value);
  40. }
  41. }
  42. }