flutter - 在 Flutter 中使用 network_image_mock 包进行图像测试
问题描述
我正在尝试测试一个有Image.network
孩子的小部件。
提供以下日志。
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following _CastError was thrown resolving an image codec:
type 'Null' is not a subtype of type 'List<int>' in type cast
When the exception was thrown, this was the stack:
#1 _MockHttpResponse.drain (package:flutter_test/src/_binding_io.dart:364:22)
#2 NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:99:24)
<asynchronous suspension>
<asynchronous suspension>
(elided 2 frames from dart:async and package:stack_trace)
我的测试:
testWidgets('My new test', (WidgetTester tester) async {
mockNetworkImagesFor(() async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ScreenWidget(),
),
),
);
final myImageFinder = find.byKey(const Key('TheImageWidget'));
expect(myImageFinder, findsOneWidget);
});
});
在上面的代码示例中,ScreenWidget
有一个孩子是Image.network
.
有什么想法吗?
解决方案
你的小部件没有回报,所以你称之为它的列表仍然是空的并且颤动不喜欢它。
推荐阅读
- rdf - OWL rdfs:langString maxCardinality 每种语言
- powershell - dotnetcore/批处理脚本退出代码
- ansible - 我可以在使用 --limit 标志运行 playbook 时获取库存文件中所有主机的 ips 吗?
- vue.js - 使用 Nuxt.js 从页面组件的 asyncData() 方法调用 mixin 函数
- html - html定位问题,需要定位section
- python - Cloudfront URL 永不过期
- c# - RabbitMQ 消息处于 Unacked 状态
- ruby-on-rails - 设计 destroy_user_session_path 不适用于 digitalocean
- computer-science - 寻找非确定性有限自动机语言
- android - Android Studio:WebView.onCreateInputConnection 的问题