【问题标题】:Unhandled Exception: Connection reset by peer flutter未处理的异常:连接由对等颤动重置
【发布时间】:2023-02-15 19:30:48
【问题描述】:

我制作了一个小应用程序,该应用程序从 api 互联网获取数据。它的工作,但有时应用程序失去与互联网的连接,我收到此消息错误:

E/flutter ( 3931): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Connection reset by peer
E/flutter ( 3931): #0      IOClient.send (package:http/src/io_client.dart:88:7)
E/flutter ( 3931): <asynchronous suspension>
E/flutter ( 3931): #1      BaseClient._sendUnstreamed (package:http/src/base_client.dart:93:32)
E/flutter ( 3931): <asynchronous suspension>
E/flutter ( 3931): #2      _withClient (package:http/http.dart:164:12)
E/flutter ( 3931): <asynchronous suspension>

我正在使用最新版本的 http 库。 SDK flutter 3.3.0 版本。


Future fetchMain() async {

  var response = await http.get(Uri.parse('https://************.php'));
  if (response.statusCode == 200) {
     final Data = json.decode(response.body).cast<Map<String, dynamic>>();
     List<MainModel> ListData = Data.map<MainModel>(
             (json) {
           return MainModel.fromJson(json);
         }).toList();
     return ListData;

  } else {

  }
}

连接与 Internet 断开连接约 3 分钟,然后再次工作。

任何人都知道这个问题以及我如何解决它?

谢谢。

【问题讨论】:

    标签: flutter


    【解决方案1】:

    在 fetchMain 函数中放置一个 try-catch 块并处理可能的错误

    【讨论】:

      猜你喜欢
      • 2021-04-12
      • 2012-06-02
      • 2014-01-01
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      • 2019-11-27
      • 2017-04-12
      • 1970-01-01
      相关资源
      最近更新 更多