【问题标题】:Getx HttpClient is not working, I have tried everything thats on the internetGetx HttpClient 不起作用,我已经尝试了互联网上的所有内容
【发布时间】: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


【解决方案1】:

像这样改变你的代码;

httpClient.addResponseModifier((request, response) async {
  print(response.body);
  return response; // add this
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 2021-09-05
    • 2022-06-11
    • 2013-05-08
    • 2022-09-30
    相关资源
    最近更新 更多