为什么 MacOS 桌面版 Flutter 上的 HTTP 请求在发布版上不起作用?

use*_*958 1 macos xcode http android-studio flutter

我正在制作 HTTP 调试或配置文件构建,并且工作正常。但如果我切换到 Release 它就不再起作用了

\n
 [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: SocketException: Failed host lookup: '*******.*******.*****.io' (OS Error: nodename nor servname provided, or not known, errno = 8)\n#0      _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:681)\n#1      _RawSocket.startConnect (dart:io-patch/socket_patch.dart:1808)\n#2      RawSocket.startConnect (dart:io-patch/socket_patch.dart:27)\n#3      RawSecureSocket.startConnect (dart:io/secure_socket.dart:237)\n#4      SecureSocket.startConnect (dart:io/secure_socket.dart:60)\n#5      _ConnectionTarget.connect (dart:_http/http_impl.dart:2437)\n#6      _HttpClient._getConnection.connect (dart:_http/http_impl.dart:2808)\n#7      _HttpClient._getConnection (dart:_http/http_impl.dart:2813)\n
Run Code Online (Sandbox Code Playgroud)\n

我认为这是互联网权限问题,但我找不到需要添加权限的位置(info.plist?)以及需要添加哪些权限?

\n
[\xe2\x9c\x93] Connected device (3 available)\n    \xe2\x80\xa2 iPad Pro (12.9-inch) (5th generation) (mobile) \xe2\x80\xa2 00008103-000E44D10C3B001E \xe2\x80\xa2 ios            \xe2\x80\xa2 iOS 15.1 19B74\n    \xe2\x80\xa2 macOS (desktop)                                \xe2\x80\xa2 macos                     \xe2\x80\xa2 darwin-arm64   \xe2\x80\xa2 macOS 12.0.1 21A559 darwin-arm\n    \xe2\x80\xa2 Chrome (web)                                   \xe2\x80\xa2 chrome                    \xe2\x80\xa2 web-javascript \xe2\x80\xa2 Google Chrome 96.0.4664.110\n
Run Code Online (Sandbox Code Playgroud)\n

小智 6

查看MacOS flutter 文档。

macos/Runner/DebugProfile.entitlements在和中添加以下行macos/Runner/Release.entitlements

<key>com.apple.security.network.client</key>
<true/>
Run Code Online (Sandbox Code Playgroud)