扑来 - 如何在小部件测试中测试特定的lottie动画
嗨,我有一个Lottiebuilder Wichh通过资产的JSON加载动画。
LottieBuilder.asset(
'assets/animations/no_wifi_animation.json',
repeat: true),
我想编写一个测试以确定Bieng的特定JSON动画,所以我写了这样的测试:
testWidgets('NotConnectedScreen LottieBuilder plays the correct Animation',
(tester) async {
final lottieBilder =
LottieBuilder.asset('assets/animations/no_wifi_animation.json');
await tester.pumpWidget(myApp);
expect(find.byWidget(lottieBilder), findsOneWidget);
});
我制作了一个假资产构建器,并将我的家用小部件包裹在它上:
class FakeAssetsBundle extends Fake implements AssetBundle{
final String animationJson = File('assets/animations/no_wifi_animation.json').readAsStringSync();
@override
Future<String> loadString(String key, {bool cache = true}) async{
return animationJson;
}
}
我的主要功能看起来像这样:
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late Widget myApp;
late FakeAssetsBundle fakeAssetsBundle;
setUp(() {
fakeAssetsBundle = FakeAssetsBundle();
myApp = MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: DefaultAssetBundle(
bundle: fakeAssetsBundle,
child: const NotConnectedScreen()),
);
});
testWidgets('NotConnectedScreen LottieBuilder plays the correct Animation',
(tester) async {
final lottieBilder =
LottieBuilder.asset('assets/animations/no_wifi_animation.json');
await tester.pumpWidget(myApp);
expect(find.byWidget(lottieBilder), findsOneWidget);
});
}
仍然是测试 : t通过,任何帮助都将得到很大的批准。
Hi I have a LottieBuilder wichh loads an animation via json from assets.
LottieBuilder.asset(
'assets/animations/no_wifi_animation.json',
repeat: true),
i want to a write a test to determine that the specific json animation is bieng rendered so i wrote a test like this :
testWidgets('NotConnectedScreen LottieBuilder plays the correct Animation',
(tester) async {
final lottieBilder =
LottieBuilder.asset('assets/animations/no_wifi_animation.json');
await tester.pumpWidget(myApp);
expect(find.byWidget(lottieBilder), findsOneWidget);
});
i made a fake AssetBuilder and wrapped my home widget around it :
class FakeAssetsBundle extends Fake implements AssetBundle{
final String animationJson = File('assets/animations/no_wifi_animation.json').readAsStringSync();
@override
Future<String> loadString(String key, {bool cache = true}) async{
return animationJson;
}
}
and my main function looks like this :
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late Widget myApp;
late FakeAssetsBundle fakeAssetsBundle;
setUp(() {
fakeAssetsBundle = FakeAssetsBundle();
myApp = MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: DefaultAssetBundle(
bundle: fakeAssetsBundle,
child: const NotConnectedScreen()),
);
});
testWidgets('NotConnectedScreen LottieBuilder plays the correct Animation',
(tester) async {
final lottieBilder =
LottieBuilder.asset('assets/animations/no_wifi_animation.json');
await tester.pumpWidget(myApp);
expect(find.byWidget(lottieBilder), findsOneWidget);
});
}
still the test doesn't pass , any help would be much apprieciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论