【发布时间】:2021-12-07 08:04:32
【问题描述】:
我已经在提供程序类中使用 getx getconnect 实现了网络调用的自定义配置,但它没有按预期工作。我还检查了使用调试它正在初始化提供程序类,但没有在提供程序类中设置 baseUrl 和身份验证令牌等。我还在绑定类中调用了它,并且在绑定中它位于所有控制器之上。
提供者初始化代码:
httpClient.baseUrl = "https://myUrl";
httpClient.defaultContentType = "application/json";
httpClient.timeout = Duration(seconds: 100);
httpClient.addResponseModifier((request, response) async {
print(response.body);
});
httpClient.addRequestModifier<dynamic>((request) async {
// add request here
return request;
});
var headers = {'Authorization': "Bearer $token"};
httpClient.addAuthenticator<dynamic>((request) async {
request.headers.addAll(headers);
return request;
});
class DataBinding extends Bindings{
@override
void dependencies() {
Get.put(Provider());
Get.lazyPut(() => AuthController(),fenix: true);
Get.lazyPut(() => LocationController(),fenix: true);
Get.lazyPut(() => ServicesController(),fenix: true);
Get.lazyPut(() => ConfirmRideController(),fenix: true);
Get.lazyPut(() => HomeController(),fenix: true);
Get.lazyPut(() => HelperController(),fenix: true);
Get.lazyPut(() => UserCardController(),fenix: true);
Get.lazyPut(() => ProfileController(),fenix: true);
Get.lazyPut(() => RequestController(), fenix: true);
Get.lazyPut(() => TripController(),fenix: true);
Get.lazyPut(() => VoucherController(),fenix: true);
Get.lazyPut(() => InvoiceController(),fenix: true);
Get.lazyPut(() => HelpController(),fenix: true);
}
}
【问题讨论】:
-
能否请您添加您的提供程序类的完整代码?
标签: flutter dart httpclient flutter-getx