Provide precache function for golden tests
I tried to use a LottieBuilder as part of a golden test like this
Column(children: <Widget>[
Icon(Icons.text_fields),
Text('Test', style: TextStyle(fontFamily: 'Bangers')),
Lottie.asset('assets/lottie/test.json', repeat: false),
Image.asset('assets/images/test.png'),
])
Inside the widget test I try to wait for the LottieProvider to finish loading (LottieProvider.load().then(…)) but while I managed to render other images and fonts, I still fail to get an Image.
A precache function similar to widgets/precacheImage would be very helpful.
Hi, Thanks for the feature request.
I've needed this feature too but it was a bit tricky to implement correctly so I put it aside for now. I may try again soon.
My current workaround is something like:
testWidgets('My golden test', (tester) async {
await tester.runAsync(() => AssetLottie('asset/lottie/test.json').load());
// Do actual golden test...
});
Thanks for this excellent package!
I would also find precache functionality useful, but I'm not familiar enough with the code to know how to implement it. The package flutter_svg has this functionality, so perhaps ideas from there can be used. See https://pub.dev/documentation/flutter_svg/latest/svg/precachePicture.html https://stackoverflow.com/questions/62257156/how-to-use-precachepicture-in-flutter-svg
Example usage:
Future<void> main() async {
await precachePicture(ExactAssetPicture(SvgPicture.svgStringDecoder, 'assets/images/image.svg'), null);
runApp(YourApp());
}