diox_cookie_manager 2.1.0-dev.1 copy "diox_cookie_manager: ^2.1.0-dev.1" to clipboard
diox_cookie_manager: ^2.1.0-dev.1 copied to clipboard

discontinuedreplaced by: dio_cookie_manager
outdated

A cookie manager for Dio, which supports persistent cookies in RAM and file.

diox_cookie_manager #

Pub

A cookie manager for diox.

Getting Started #

Install #

dependencies:
  diox_cookie_manager: ^2.0.0 # latest version

Usage #

import 'package:cookie_jar/cookie_jar.dart';
import 'package:diox/diox.dart';
import 'package:diox_cookie_manager/diox_cookie_manager.dart';

void main() async {
  final dio =  Dio();
  final cookieJar = CookieJar();
  dio.interceptors.add(CookieManager(cookieJar));
  // First request, and save cookies (CookieManager do it).
  await dio.get("https://dart.dev");
  // Print cookies
  print(await cookieJar.loadForRequest(Uri.parse("https://dart.dev")));
  // Second request with the cookies
  await dio.get('https://dart.dev');
}

CookieManager Interceptor can help us manage the request/response cookies automatically. CookieManager depends on the cookie_jar package:

The diox_cookie_manager manage API is based on the withdrawn cookie_jar.

You can create a CookieJar or PersistCookieJar to manage cookies automatically, and dio use the CookieJar by default, which saves the cookies in RAM. If you want to persists cookies, you can use the PersistCookieJar class, for example:

dio.interceptors.add(CookieManager(PersistCookieJar()))

PersistCookieJar persists the cookies in files, so if the application exit, the cookies always exist unless call delete explicitly.

Note: In flutter, the path passed to PersistCookieJar must be valid (exists in phones and with write access). Use path_provider package to get the right path.

In flutter:

Future<void> prepareJar() async {
  final Directory appDocDir = await getApplicationDocumentsDirectory();
  final String appDocPath = appDocDir.path;
  final jar = PersistCookieJar(
    ignoreExpires: true,
    storage: FileStorage(appDocPath +"/.cookies/" ),
  );
  dio.interceptors.add(CookieManager(jar));
}
0
likes
0
points
33
downloads

Publisher

verified publisherflutter.cn

Weekly Downloads

A cookie manager for Dio, which supports persistent cookies in RAM and file.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

cookie_jar, diox

More

Packages that depend on diox_cookie_manager