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: _Item(
child: Lottie.asset( child: Lottie.asset(
assetName, assetName,
onWarning: _logger.info, onWarning: (w) => _logger.info('$assetName - $w'),
frameBuilder: (context, child, composition) { frameBuilder: (context, child, composition) {
return AnimatedOpacity( return AnimatedOpacity(
opacity: composition == null ? 0 : 1, opacity: composition == null ? 0 : 1,

View File

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

View File

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

View File

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

View File

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