dio_util.dart 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. class NetworkUtil {
  9. ///获取几大洲列表
  10. Future<List<ContinentEntity>> getContinentList() async {
  11. var response =
  12. await Dio().get("${AppConfig.baseUrl}api/home/visa/part/list");
  13. var data = json.decode(response.toString());
  14. return BaseModelEntity<List<ContinentEntity>>.fromJson(data).data;
  15. }
  16. ///获取每个洲对应国家列表
  17. Future<List<CountryEntity>> getCountryList(int id) async {
  18. var queryParams = {"part_id": id};
  19. var response = await Dio().get(
  20. "${AppConfig.baseUrl}/api/home/visa/country/list",
  21. queryParameters: queryParams);
  22. var data = json.decode(response.toString());
  23. return BaseModelEntity<List<CountryEntity>>.fromJson(data).data;
  24. }
  25. ///获取国家详情
  26. Future<CountryDetailEntity> getCountryDetail(int id) async {
  27. var queryParams = {"country_id": id};
  28. var response = await Dio().get(
  29. "${AppConfig.baseUrl}api/home/visa/country/detail",
  30. queryParameters: queryParams);
  31. var data = json.decode(response.toString());
  32. return BaseModelEntity<CountryDetailEntity>.fromJson(data).data;
  33. }
  34. }