dio库
dio | Dart Package

一、安装

Use this package as a library

Depend on it

Run this command:

With Dart:

$ dart pub add dio

With Flutter:

$ flutter pub add dio

This will add a line like this to your package’s pubspec.yaml (and run an implicit dart pub get):

dependencies: dio: ^4.0.0

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

Import it

Now in your Dart code, you can use:

import ‘package:dio/dio.dart’;

二、使用

image.png

  1. import 'package:dio/dio.dart';
  2. void getHttp() async {
  3. try {
  4. var response = await Dio().get('http://www.google.com');
  5. print(response);
  6. } catch (e) {
  7. print(e);
  8. }
  9. }

awesome-dio

🎉 A curated list of awesome things related to dio.

Plugins

Plugins Description
dio_cookie_manager A cookie manager for Dio
dio_http2_adapter A Dio HttpClientAdapter which support Http/2.0
dio_flutter_transformer A Dio transformer especially for flutter, by which the json decoding will be in background with compute function.
dio_http_cache A cache library for Dio, like Rxcache
in Android. dio-http-cache uses sqflite
as disk cache, and LRU
strategy as memory cache.
retrofit retrofit.dart is an dio client generator using source_gen and inspired by Chopper and Retrofit.
dio_firebase_performance A Dio Interceptor for reporting network metrics to Firebase
postman_dio A Dio Logger Interceptor for export to ‘Postman Collection’.json