1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import 'package:cookie_jar/cookie_jar.dart';
- class CookieJarImpl implements CookieJar {
- static const String _COOKIE_KEY_AUTH = 'ky_auth';
- static const String _COOKIE_KEY_SDK = 'sdk';
- static const String _COOKIE_AUTH_SAVE_KEY = 'KeyAuthCookie';
- void saveCookieValue(String value) {
- //save cookie into sp
- }
- String getCookieValue() {
- //get cookie from sp
- return "";
- }
- @override
- bool get ignoreExpires => false;
- @override
- Future<void> delete(Uri uri, [bool withDomainSharedCookie = false]) {
- // TODO: implement delete
- throw UnimplementedError();
- }
- @override
- Future<void> deleteAll() {
- // TODO: implement deleteAll
- throw UnimplementedError();
- }
- @override
- Future<List<Cookie>> loadForRequest(Uri uri) {
- List<Cookie> cookies = [];
- var cookie1 = Cookie(_COOKIE_KEY_SDK, '28')..domain = uri.host;
- cookies.add(cookie1);
- var cookie2 = Cookie(_COOKIE_KEY_AUTH, getCookieValue())..domain = uri.host;
- cookies.add(cookie2);
- return Future.value(cookies);
- }
- @override
- Future<void> saveFromResponse(Uri uri, List<Cookie> cookies) {
- Cookie cookieValue =
- cookies.singleWhere((element) => element.name == _COOKIE_KEY_AUTH);
- if (cookieValue != null) {
- saveCookieValue(cookieValue.value);
- }
- }
- }
|