dio_util.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import 'dart:convert';
  2. import 'package:dio/dio.dart';
  3. import 'package:hengyi/config/config.dart';
  4. import 'package:hengyi/data/base_model_entity.dart';
  5. import 'package:hengyi/data/continent_entity.dart';
  6. import 'package:hengyi/data/country_detail_entity.dart';
  7. import 'package:hengyi/data/country_entity.dart';
  8. import 'package:hengyi/data/web_config_entity.dart';
  9. class NetworkUtil {
  10. ///获取几大洲列表
  11. Future<List<ContinentEntity>> getContinentList() async {
  12. var response =
  13. await Dio().get("${AppConfig.baseUrl}api/home/visa/part/list");
  14. var data = json.decode(response.toString());
  15. return BaseModelEntity<List<ContinentEntity>>.fromJson(data).data;
  16. }
  17. ///获取每个洲对应国家列表
  18. Future<List<CountryEntity>> getCountryList(int id) async {
  19. var queryParams = {"part_id": id};
  20. var response = await Dio().get(
  21. "${AppConfig.baseUrl}/api/home/visa/country/list",
  22. queryParameters: queryParams);
  23. var data = json.decode(response.toString());
  24. return BaseModelEntity<List<CountryEntity>>.fromJson(data).data;
  25. }
  26. ///获取国家详情
  27. Future<CountryDetailEntity> getCountryDetail(int id) async {
  28. var queryParams = {"country_id": id};
  29. var response = await Dio().get(
  30. "${AppConfig.baseUrl}api/home/visa/country/detail",
  31. queryParameters: queryParams);
  32. var data = json.decode(response.toString());
  33. return BaseModelEntity<CountryDetailEntity>.fromJson(data).data;
  34. }
  35. ///获取网站配置信息
  36. Future<WebConfigEntity> getWebConfig() async {
  37. var response =
  38. await Dio().get("${AppConfig.baseUrl}api/home/visa/web/config");
  39. var data = json.decode(response.toString());
  40. return BaseModelEntity<WebConfigEntity>.fromJson(data).data;
  41. }
  42. }