pq_network 0.0.10 copy "pq_network: ^0.0.10" to clipboard
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
100
pub points
0%
popularity

Publisher

unverified uploader

A new Flutter package.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

dio, flutter

More

Packages that depend on pq_network