Ary*_*dav 6 dart-pub flutter flutter-dependencies flutter-getx
我正在尝试加载产品列表,并且正在使用 CachedNetworkImage (或者如果我也使用 Image.network)来显示该特定产品的图像。
\n我使用了 Error Builder 属性,这样如果图像出现错误,则显示默认资源图像并且工作正常。直到我将另一个页面推到它上面,然后我在调试控制台中收到以下内容。
\nI/flutter (21932): \xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE \xe2\x95\x9e\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\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nI/flutter (21932): The following NetworkImageLoadException was thrown resolving an image codec:\nI/flutter (21932): HTTP request failed, statusCode: 404, https://***.com/url.jpg\n\nRun Code Online (Sandbox Code Playgroud)\n但是,我在某处读到,如果我们收到此类错误,则忽略它,因为 CachedNetoworkImage 作者也在他的最后一行文档中说了同样的话。但问题是我还使用 Firebase Crashlytics 来显示崩溃和错误(如果有)。
\n问题是由于这个异常,我收到了非致命错误。因此,即使 1 个用户正在使用我的应用程序,他们也不会在屏幕上看到任何错误,但如果我使用 crashlytics,我会收到该特定用户的超过 48 个非致命错误。\n
这是我用于显示产品列表及其图像的代码\n ProductTile.dart
\nimport \'package:applicationName/views/product_page/model/ProductModel.dart\';\nimport \'package:flutter/material.dart\';\nimport \'package:cached_network_image/cached_network_image.dart\';\nimport \'package:get/get.dart\';\n\nclass ProductTile extends StatelessWidget {\n final Product product;\n const ProductTile(this.product);\n @override\n Widget build(BuildContext context) {\n return InkWell(\n onTap: () {\n Get.toNamed("/productDetailPage/${product.prodId}");\n },\n child: Card(\n elevation: 2,\n child: Column(\n crossAxisAlignment: CrossAxisAlignment.start,\n children: [\n Row(\n crossAxisAlignment: CrossAxisAlignment.center,\n children: [\n Container(\n decoration: BoxDecoration(\n borderRadius: BorderRadius.only(\n bottomRight: Radius.circular(8.0)),\n color: Colors.indigo,\n ),\n padding: EdgeInsets.all(4.0),\n child: Text(\n "${product.discount}% OFF",\n textScaleFactor: 0.8,\n style: TextStyle(\n color: Colors.white,\n ),\n maxLines: 2,\n overflow: TextOverflow.ellipsis,\n ),\n ),\n SizedBox(width: 10),\n ],\n ),\n Container(\n // color: Colors.red,\n child: Image.network(\n product.image,\n errorBuilder: (BuildContext context, Object exception,\n StackTrace stackTrace) {\n // Appropriate logging or analytics, e.g.\n // myAnalytics.recordError(\n // \'An error occurred loading "https://example.does.not.exist/image.jpg"\',\n // exception,\n // stackTrace,\n // );\n return Image.asset(\'assets/images/noimage.png\');\n },\n )\n //I commented this to check if same is happening with Image.network() also or not and it\'s happening in //it too.\n // CachedNetworkImage(\n // alignment: Alignment.center,\n // imageUrl: product.image,\n // placeholder: (context, url) =>\n // Center(child: CircularProgressIndicator()),\n // errorWidget: (context, url, error) =>\n // Image.asset(\'assets/images/noimage.png\'),\n // ),\n ),\n SizedBox(height: 8),\n Padding(\n padding: const EdgeInsets.only(left: 8.0),\n child: Text(\n product.prodName,\n maxLines: 2,\n style: TextStyle(\n fontFamily: \'avenir\', fontWeight: FontWeight.w800),\n overflow: TextOverflow.ellipsis,\n ),\n ),\n SizedBox(height: 8),\n Padding(\n padding: const EdgeInsets.only(left: 8.0),\n child: Flex(\n direction: Axis.vertical,\n children: [\n Text(\n // "Some Text",\n // \'\xe2\x82\xb9${double.parse(product.fprice).toStringAsFixed(2)}\',\n double.tryParse(product.priceFormat) is double\n ? "\xe2\x82\xb9${double.tryParse(product.priceFormat).toStringAsFixed(2)}"\n : "${product.priceFormat}",\n style: TextStyle(\n // fontSize: 20,\n fontFamily: \'avenir\',\n decoration: TextDecoration.lineThrough),\n ),\n ],\n ),\n ),\n SizedBox(height: 8),\n Padding(\n padding: const EdgeInsets.only(left: 8.0, bottom: 8.0),\n child: Flex(\n direction: Axis.vertical,\n children: [\n Text(\n // "Some Text",\n //\n // product.price is String\n // ? \'\xe2\x82\xb9${double.parse(product.price).toStringAsFixed(2)}\'\n // : \'\xe2\x82\xb9${product.price.toStringAsFixed(2)}\',\n double.tryParse(product.fpriceFormat) is double\n ? "\xe2\x82\xb9${double.tryParse(product.fpriceFormat).toStringAsFixed(2)}"\n : "${product.fpriceFormat}",\n style: TextStyle(\n // fontSize: 15,\n fontFamily: \'avenir\',\n ),\n ),\n ],\n ),\n ),\n ],\n ),\n ),\n );\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n无论我在上述页面之后推送哪个页面,我仍然会在控制台中收到该异常。
\n也许使用 运行应用程序是个好主意runZoned。所以这就是你应该如何做的。
import 'dart:async';
void main() {
runZoned(
() => MyApp(),
(error, stackStrace) {
// Handle errors here :)
// Check for error from `CachedNetworkImage`.
},
);
}
Run Code Online (Sandbox Code Playgroud)
希望这有帮助:D
| 归档时间: |
|
| 查看次数: |
894 次 |
| 最近记录: |