封装dio库

为了更好的使用对dio网络库进行二次封装

安装使用

dependencies:
  dio_repository: ^1.1.2

主项目中引入

DSHttpInject httpInject = DSHttpInject(
    onRequest:(options,handler){
        //做请求的拦截处理
      handler.next(options);
    },onResponse:(options,handler){
        //做响应的拦截处理
      handler.next(options);
    },onError:(options,handler){
        //异常错误处理
      handler.next(options);
    },
  );

  DSDioUtil.getInstance().init(
    baseUrl: 'xxx',
    connectTimeout: 2000,
    inject:httpInject
  );

网络库模块使用

dynamic data = await DSDioUtil.getInstance().get('/xxxx',queryParameters:{'key':'value'});