dio_cookie_manager 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new93

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));
...

[1.0.0] - 2019.9.18

  • First stable version

[0.0.1] - 2019.9.17

  • A cookie manager for Dio.

example/example.dart

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

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

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dio_cookie_manager: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dio_cookie_manager/dio_cookie_manager.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
87
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
93
Learn more about scoring.

We analyzed this package on Oct 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:dio_cookie_manager/dio_cookie_manager.dart with components: io.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >2.4.0 <3.0.0
cookie_jar ^1.0.1 1.0.1
dio ^3.0.0 3.0.3
Transitive dependencies
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
meta 1.1.7
path 1.6.4
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
pedantic 1.1.0
test ^1.5.1
test_coverage ^0.2.0