Fix onWarning callback (#156)

This commit is contained in:
Xavier H
2021-07-08 21:58:01 +02:00
committed by GitHub
parent cb929e791d
commit a52977f2b3
5 changed files with 16 additions and 9 deletions

View File

@ -42,7 +42,7 @@ class App extends StatelessWidget {
child: _Item(
child: Lottie.asset(
assetName,
onWarning: _logger.info,
onWarning: (w) => _logger.info('$assetName - $w'),
frameBuilder: (context, child, composition) {
return AnimatedOpacity(
opacity: composition == null ? 0 : 1,

View File

@ -14,7 +14,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.5.0"
boolean_selector:
dependency: transitive
description:

View File

@ -99,9 +99,11 @@ class LottieComposition {
WarningCallback? onWarning;
void addWarning(String warning) {
_warnings.add(warning);
var isNew = _warnings.add(warning);
if (isNew) {
onWarning?.call(warning);
}
}
void incrementMatteOrMaskCount(int amount) {
_maskAndMatteCount += amount;

View File

@ -436,9 +436,16 @@ class _LottieBuilderState extends State<LottieBuilder> {
void _load() {
var provider = widget.lottie;
_loadingFuture = widget.lottie.load().then((composition) {
if (mounted && widget.onLoaded != null && widget.lottie == provider) {
composition.onWarning = widget.onWarning;
widget.onLoaded!(composition);
if (mounted && widget.lottie == provider) {
var onWarning = widget.onWarning;
composition.onWarning = onWarning;
if (onWarning != null) {
for (var warning in composition.warnings) {
onWarning(warning);
}
}
widget.onLoaded?.call(composition);
}
return composition;

View File

@ -84,8 +84,6 @@ class ContentModelParser {
break;
case 'mm':
model = MergePathsParser.parse(reader);
composition.addWarning('Animation contains merge paths. '
'Merge paths must be manually enabled by settings enableMergePaths.');
break;
case 'rp':
model = RepeaterParser.parse(reader, composition);