dio_cookie_manager 1.0.0

Dart native
Flutter Android iOS

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

dio_cookie_manager Pub #

A cookie manager for Dio.

Getting Started #

Install #

dependencies:
  dio_cookie_manager: 1.0.x  #latest version

Usage #

import 'package:dio/dio.dart';
import 'package:dio_cookie_manager/cookie_manager.dart';
import 'package:cookie_jar/cookie_jar.dart';

main() async {
  var dio =  Dio();
  var cookieJar=CookieJar();
  dio.interceptors.add(CookieManager(cookieJar));
  // Print cookies
  print(cookieJar.loadForRequest(Uri.parse("https://baidu.com/")));
  // second request with the cookie
  await dio.get("https://baidu.com/");
  ... 
}

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

The dio_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). you can use path_provider package to get right path.

In flutter:

Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path;
var cookieJar=PersistCookieJar(dir:appdocPath+"/.cookies/");
dio.interceptors.add(CookieManager(cookieJar));
...
13
likes
90
pub points
95%
popularity

Publisher

flutterchina.club

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

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

unknown (LICENSE)

Dependencies

cookie_jar, dio

More

Packages that depend on dio_cookie_manager