這裏我的用例是顯示快餐欄,如果有錯誤,但由於我不打電話給load:我無法捕捉到SocketException。如何捕捉抖動解決NetworkImage時拋出的異常?
更新(例如堆棧跟蹤):
I/flutter (11702): ══╡ EXCEPTION CAUGHT BY SERVICES ╞══════════════════════════════════════════════════════════════════
I/flutter (11702): The following SocketException was thrown resolving a single-frame image stream:
I/flutter (11702): Connection failed (OS Error: Network is unreachable, errno = 101), address = ((snip)), port
I/flutter (11702): = 443
I/flutter (11702): When the exception was thrown, this was the stack:
I/flutter (11702): #0 IOClient.send (package:http/src/io_client.dart:30:23)
I/flutter (11702): <asynchronous suspension>
I/flutter (11702): #1 BaseClient._sendUnstreamed (package:http/src/base_client.dart:171:38)
I/flutter (11702): <asynchronous suspension>
I/flutter (11702): #2 BaseClient.get (package:http/src/base_client.dart:34:5)
I/flutter (11702): #3 NetworkImage._loadAsync (package:flutter/src/services/image_provider.dart:431:54)
I/flutter (11702): <asynchronous suspension>
I/flutter (11702): #4 NetworkImage.load (package:flutter/src/services/image_provider.dart:417:7)
I/flutter (11702): #5 ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/services/image_provider.dart:253:61)
感謝您的回答,但我不確定這是否正確。從文檔中,NetworkImage是一個常量構造函數,圖像的實際加載發生在ImageStreamCompleter中,而不是在創建ImageProvider時發生。 – perlatus