import 'package:domain/constants/api_constants.dart'; import 'package:plugin_basic/constants/app_constant.dart'; import 'package:plugin_platform/engine/sp/sp_util.dart'; import 'package:plugin_platform/http/http_provider.dart'; import '../basic_export.dart'; import '../dio_interceptors/interceptor_auth_dio.dart'; import '../dio_interceptors/interceptor_status_code_dio.dart'; class HttpProviderInjection { // 设置默认的 static void putHttpProviderByCountry() { //根据选中的国家赋值Api String baseUrl; int country = SPUtil.getInt(AppConstant.storageSelectedCountry, defValue: 0) ?? 0; if (country == 1) { baseUrl = ApiConstants.sgBaseUrl; } else { baseUrl = ApiConstants.baseUrl; } //注入 HttpProvider Get.put( HttpProvider( baseUrl, interceptors: [StatusCodeDioInterceptors(), AuthDioInterceptors()], //需要加上与App关联的一些拦截处理 ), permanent: true); } // 切换应用的BaseUrl的逻辑 static void switchBaseUrl(String baseUrl) { //找到单例对象 HttpProvider,切换域名 HttpProvider httpProvider = Get.find(); httpProvider.switchBaseUrl(baseUrl); } }