[Flutter] SocketException on macOS
2024.09.09
3λΆ
While building and running for MacOS in Flutter, I met the following error:
======== Exception caught by image resource service ================================================
The following SocketException was thrown resolving an image codec:
Connection failed (OS Error: Operation not permitted, errno = 1), address = someurl.com, port = 443
When the exception was thrown, this was the stack:
#0 _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:721:35)
#1 _RawSocket.startConnect (dart:io-patch/socket_patch.dart:1914:26)
#2 RawSocket.startConnect (dart:io-patch/socket_patch.dart:27:23)
#3 RawSecureSocket.startConnect (dart:io/secure_socket.dart:299:22)
#4 SecureSocket.startConnect (dart:io/secure_socket.dart:77:28)
#5 _ConnectionTarget.connect (dart:_http/http_impl.dart:2480:26)
#6 _HttpClient._getConnection.connect (dart:_http/http_impl.dart:2923:12)
#7 _HttpClient._getConnection (dart:_http/http_impl.dart:2928:12)
#8 _HttpClient._openUrl (dart:_http/http_impl.dart:2783:12)
#9 _HttpClient.getUrl (dart:_http/http_impl.dart:2625:48)
#10 NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:104:59)
#11 NetworkImage.loadImage (package:flutter/src/painting/_network_image_io.dart:66:14)
#12 ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:520:39)
#13 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:377:22)
#14 ImageProvider.resolveStreamForKey (package:flutter/src/painting/image_provider.dart:517:81)
#15 ScrollAwareImageProvider.resolveStreamForKey (package:flutter/src/widgets/scroll_aware_image_provider.dart:104:19)
#16 ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:366:9)
#17 ImageProvider._createErrorHandlerAndKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:479:24)
#18 SynchronousFuture.then (package:flutter/src/foundation/synchronous_future.dart:43:39)
#19 ImageProvider._createErrorHandlerAndKey (package:flutter/src/painting/image_provider.dart:476:9)
#20 ImageProvider.resolve (package:flutter/src/painting/image_provider.dart:363:5)
#21 _ImageState._resolveImage (package:flutter/src/widgets/image.dart:1111:16)
#22 _ImageState.didChangeDependencies (package:flutter/src/widgets/image.dart:1061:5)
#23 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5636:11)
#24 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5463:5)
#25 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4340:16)
#26 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6904:36)
#27 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6916:32)
... Normal element mounting (25 frames)
#52 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4340:16)
#53 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6904:36)
#54 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6916:32)
... Normal element mounting (140 frames)
#194 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4340:16)
#195 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6904:36)
#196 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6916:32)
... Normal element mounting (186 frames)
#382 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4340:16)
#383 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6904:36)
#384 Element.updateChild (package:flutter/src/widgets/framework.dart:3849:18)
#385 Element.updateChildren (package:flutter/src/widgets/framework.dart:4036:32)
#386 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6929:17)
#387 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#388 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#389 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5650:11)
#390 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#391 StatefulElement.update (package:flutter/src/widgets/framework.dart:5673:5)
#392 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#393 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#394 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#395 ProxyElement.update (package:flutter/src/widgets/framework.dart:5816:5)
#396 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#397 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#398 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#399 ProxyElement.update (package:flutter/src/widgets/framework.dart:5816:5)
#400 _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:105:11)
#401 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#402 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#403 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5650:11)
#404 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#405 StatefulElement.update (package:flutter/src/widgets/framework.dart:5673:5)
#406 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#407 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#408 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#409 ProxyElement.update (package:flutter/src/widgets/framework.dart:5816:5)
#410 _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:105:11)
#411 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#412 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#413 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5650:11)
#414 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#415 StatefulElement.update (package:flutter/src/widgets/framework.dart:5673:5)
#416 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#417 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#418 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5650:11)
#419 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#420 StatefulElement.update (package:flutter/src/widgets/framework.dart:5673:5)
#421 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#422 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6776:14)
#423 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#424 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6776:14)
#425 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#426 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#427 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#428 ProxyElement.update (package:flutter/src/widgets/framework.dart:5816:5)
#429 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#430 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#431 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#432 ProxyElement.update (package:flutter/src/widgets/framework.dart:5816:5)
#433 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#434 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#435 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5650:11)
#436 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#437 StatefulElement.update (package:flutter/src/widgets/framework.dart:5673:5)
#438 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#439 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#440 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#441 ProxyElement.update (package:flutter/src/widgets/framework.dart:5816:5)
#442 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#443 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#444 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#445 ProxyElement.update (package:flutter/src/widgets/framework.dart:5816:5)
#446 _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:105:11)
#447 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#448 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#449 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5650:11)
#450 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#451 StatefulElement.update (package:flutter/src/widgets/framework.dart:5673:5)
#452 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#453 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#454 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#455 ProxyElement.update (package:flutter/src/widgets/framework.dart:5816:5)
#456 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#457 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#458 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#459 StatelessElement.update (package:flutter/src/widgets/framework.dart:5563:5)
#460 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#461 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#462 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#463 ProxyElement.update (package:flutter/src/widgets/framework.dart:5816:5)
#464 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#465 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#466 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#467 ProxyElement.update (package:flutter/src/widgets/framework.dart:5816:5)
#468 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)
#469 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)
#470 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5650:11)
#471 Element.rebuild (package:flutter/src/widgets/framework.dart:5203:7)
#472 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2905:19)
#473 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1136:21)
#474 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:443:5)
#475 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1392:15)
#476 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1313:9)
#477 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1171:5)
#478 _invoke (dart:ui/hooks.dart:312:13)
#479 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
#480 _drawFrame (dart:ui/hooks.dart:283:31)
Image provider: NetworkImage("https://someurl.com/someimage.png", scale: 1.0)
Image key: NetworkImage("https://someurl.com/someimage.png", scale: 1.0)
====================================================================================================
If you look at the error, OS ERROR
has occurred for someurl.com because it is Operation Not Permitted
.
To solve it, I opened the /macos/runner/Debugprofile.entitLements
file and added 'com.apple.secure.network.client' item.
/macos/Runner/DebugProfile.entitlements
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>