pq_network 0.0.10 icon indicating copy to clipboard operation
pq_network: ^0.0.10 copied to clipboard

A new Flutter package.

pq_network #

基于Dio的一些基础封装

  • 快速设置代理
  • log格式化,支持开启关闭
  • mock,可模拟网络请求,返回特定的数据,模拟请求时间
  • decoder集成,可以在decoder中完成json to Model

使用示例 #

配置Dio,此步骤必须要在网络请求之前

BaseOptions options = BaseOptions(
        connectTimeout: 20000,
        receiveTimeout: 30000,
        sendTimeout: 30000,
        baseUrl: "xxxxxx",
        headers: {'Content-Type': 'application/json'});
    PQNetwork.config(options);

请求示例(Mock) #

  _get() async {
    final path = "https:/xxxxx";

    final res = await PQNetwork.get(
      path,
      mock: true,
      mockData: {"msg": "OK", "data": {}, "code": 0},
    );

    print("xxxxxxxxxx get res $res"); // {"msg": "OK", "data": {}, "code": 0}
  }

请求示例 (Mock+Decoder) #

  _getAndDecoder() async {
    final path = "https://xxxxx";

    final res = await PQNetwork.get(
      path,
      decoder: (data) => MockDataEntity.fromJson(data),
      mock: true,
      mockData: {"msg": "OK", "data": {}, "code": 0},
    );

    print("xxxxxxxxxx get res $res");
  }
0
likes
120
pub points
19%
popularity

Publisher

unverified uploader

A new Flutter package.

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

dio, flutter

More

Packages that depend on pq_network