FlutterのImage.network()、NetworkImageでURLが404を返す場合にクラッシュする。
タイトルの通りなのですが回避してプレースホルダなどを表示するにはどのようにすれば良いのでしょうか。
FadeInImage、tryで囲む方法は試しました。
エラー内容
flutter: ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
flutter: The following _Exception was thrown resolving an image codec:
flutter: Exception: HTTP request failed, statusCode: 404, https://i.ytimg.com/vi/M4P9L69dH1o/default.jpg
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 NetworkImage._loadAsync
flutter: <asynchronous suspension>
flutter: #1 NetworkImage.load
flutter: #2 ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure>
flutter: #3 ImageCache.putIfAbsent
flutter: #4 ImageProvider.resolve.<anonymous closure>.<anonymous closure>
flutter: #5 SynchronousFuture.then
flutter: #6 ImageProvider.resolve.<anonymous closure>
flutter: #10 ImageProvider.resolve
flutter: #11 _ImageState._resolveImage
flutter: #12 _ImageState.didChangeDependencies
flutter: #13 StatefulElement._firstBuild
flutter: #14 ComponentElement.mount
flutter: #15 Element.inflateWidget
flutter: #16 Element.updateChild
flutter: #17 ComponentElement.performRebuild
flutter: #18 Element.rebuild
flutter: #19 ComponentElement._firstBuild
flutter: #20 ComponentElement.mount
flutter: #21 Element.inflateWidget
flutter: #22 Element.updateChild
flutter: #23 ComponentElement.performRebuild
flutter: #24 Element.rebuild
flutter: #25 ComponentElement._firstBuild
flutter: #26 ComponentElement.mount
flutter: #27 Element.inflateWidget
flutter: #28 Element.updateChild
flutter: #29 _ListTileElement._mountChild
flutter: #30 _ListTileElement.mount
flutter: #31 Element.inflateWidget
flutter: #32 Element.updateChild
flutter: #33 ComponentElement.performRebuild
flutter: #34 Element.rebuild
flutter: #35 ComponentElement._firstBuild
flutter: #36 ComponentElement.mount
flutter: #37 Element.inflateWidget
flutter: #38 Element.updateChild
flutter: #39 SingleChildRenderObjectElement.mount
flutter: #40 Element.inflateWidget
flutter: #41 Element.updateChild
flutter: #42 ComponentElement.performRebuild
flutter: #43 Element.rebuild
flutter: #44 ComponentElement._firstBuild
flutter: #45 ComponentElement.mount
flutter: #46 Element.inflateWidget
flutter: #47 Element.updateChild
flutter: #48 SingleChildRenderObjectElement.mount
flutter: #49 Element.inflateWidget
flutter: #50 Element.updateChild
flutter: #51 SingleChildRenderObjectElement.mount
flutter: #52 Element.inflateWidget
flutter: #53 Element.updateChild
flutter: #54 SingleChildRenderObjectElement.mount
flutter: #55 Element.inflateWidget
flutter: #56 Element.updateChild
flutter: #57 ComponentElement.performRebuild
flutter: #58 Element.rebuild
flutter: #59 ComponentElement._firstBuild
flutter: #60 StatefulElement._firstBuild
flutter: #61 ComponentElement.mount
flutter: #62 Element.inflateWidget
flutter: #63 Element.updateChild
flutter: #64 ComponentElement.performRebuild
flutter: #65 Element.rebuild
flutter: #66 ComponentElement._firstBuild
flutter: #67 ComponentElement.mount
flutter: #68 Element.inflateWidget
flutter: #69 Element.updateChild
flutter: #70 ComponentElement.performRebuild
flutter: #71 Element.rebuild
flutter: #72 ComponentElement._firstBuild
flutter: #73 StatefulElement._firstBuild
flutter: #74 ComponentElement.mount
flutter: #75 Element.inflateWidget
flutter: #76 Element.updateChild
flutter: #77 ComponentElement.performRebuild
flutter: #78 Element.rebuild
flutter: #79 ComponentElement._firstBuild
flutter: #80 ComponentElement.mount
flutter: #81 Element.inflateWidget
flutter: #82 Element.updateChild
flutter: #83 SingleChildRenderObjectElement.mount
flutter: #84 Element.inflateWidget
flutter: #85 Element.updateChild
flutter: #86 ComponentElement.performRebuild
flutter: #87 Element.rebuild
flutter: #88 ComponentElement._firstBuild
flutter: #89 ComponentElement.mount
flutter: #90 Element.inflateWidget
flutter: #91 Element.updateChild
flutter: #92 ComponentElement.performRebuild
flutter: #93 Element.rebuild
flutter: #94 ComponentElement._firstBuild
flutter: #95 StatefulElement._firstBuild
flutter: #96 ComponentElement.mount
flutter: #97 Element.inflateWidget
flutter: #98 Element.updateChild
flutter: #99 SingleChildRenderObjectElement.mount
flutter: #100 Element.inflateWidget
flutter: #101 Element.updateChild
flutter: #102 ComponentElement.performRebuild
flutter: #103 Element.rebuild
flutter: #104 ComponentElement._firstBuild
flutter: #105 ComponentElement.mount
flutter: #106 Element.inflateWidget
flutter: #107 Element.updateChild
flutter: #108 SingleChildRenderObjectElement.mount
flutter: #109 Element.inflateWidget
flutter: #110 Element.updateChild
flutter: #111 ComponentElement.performRebuild
flutter: #112 Element.rebuild
flutter: #113 ComponentElement._firstBuild
flutter: #114 ComponentElement.mount
flutter: #115 Element.inflateWidget
flutter: #116 Element.updateChild
flutter: #117 SingleChildRenderObjectElement.mount
flutter: #118 Element.inflateWidget
flutter: #119 Element.updateChild
flutter: #120 ComponentElement.performRebuild
flutter: #121 Element.rebuild
flutter: #122 ComponentElement._firstBuild
flutter: #123 StatefulElement._firstBuild
flutter: #124 ComponentElement.mount
flutter: #125 Element.inflateWidget
flutter: #126 Element.updateChild
flutter: #127 ComponentElement.performRebuild
flutter: #128 Element.rebuild
flutter: #129 ComponentElement._firstBuild
flutter: #130 StatefulElement._firstBuild
flutter: #131 ComponentElement.mount
flutter: #132 Element.inflateWidget
flutter: #133 Element.updateChild
flutter: #134 SingleChildRenderObjectElement.mount
flutter: #135 Element.inflateWidget
flutter: #136 Element.updateChild
flutter: #137 ComponentElement.performRebuild
flutter: #138 Element.rebuild
flutter: #139 ComponentElement._firstBuild
flutter: #140 ComponentElement.mount
flutter: #141 Element.inflateWidget
flutter: #142 Element.updateChild
flutter: #143 SingleChildRenderObjectElement.mount
Restarted application in 2,173ms.