我已经获取网络图像并使用三元运算符,我可以在其中显示网络图像,但无法显示默认资产图像,其中网络图像在网格中默认图像无效,也如此-
\n我是颤振新手
\n image: NetworkImage(products[index]\n .productImageList[0]\n )!= null\n ? NetworkImage(\n products[index].productImageList[0])\n :Image.asset("assets/defimg.jpg"),\n fit: BoxFit.fitHeight ),\nRun Code Online (Sandbox Code Playgroud)\n它在索引 0 上显示网络图像,但不会加载网络图像无效或为空的资产图像并抛出此错误 -
\n\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90 Exception caught by image resource service \xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following _Exception was thrown resolving an image codec:\nException: Invalid image data\n\nWhen the exception was thrown, this was the stack: \n#0 _futurize (dart:ui/painting.dart:5230:5)\n#1 ImageDescriptor.encoded (dart:ui/painting.dart:5098:12)\n#2 instantiateImageCodec (dart:ui/painting.dart:1998:60)\n<asynchronous suspension>\nRun Code Online (Sandbox Code Playgroud)\n之后我尝试了 try/catch -我的 try catch 代码是 --
\nchild: Builder(builder: (BuildContext context) {\n try {\n return Center(\n child: Image.network(\n products[index]\n …Run Code Online (Sandbox Code Playgroud) try-catch conditional-operator networkimageview flutter-dependencies flutter-layout
try-catch ×1