Compare commits

...

1 Commits

Author SHA1 Message Date
27b2ec471f Add errorBuilder 2020-10-12 22:07:03 +02:00
3 changed files with 49 additions and 20 deletions

View File

@ -50,6 +50,7 @@ class Lottie extends StatefulWidget {
Key key, Key key,
AssetBundle bundle, AssetBundle bundle,
LottieFrameBuilder frameBuilder, LottieFrameBuilder frameBuilder,
LottieErrorWidgetBuilder errorBuilder,
double width, double width,
double height, double height,
BoxFit fit, BoxFit fit,
@ -71,6 +72,7 @@ class Lottie extends StatefulWidget {
key: key, key: key,
bundle: bundle, bundle: bundle,
frameBuilder: frameBuilder, frameBuilder: frameBuilder,
errorBuilder: errorBuilder,
width: width, width: width,
height: height, height: height,
fit: fit, fit: fit,
@ -93,6 +95,7 @@ class Lottie extends StatefulWidget {
void Function(LottieComposition) onLoaded, void Function(LottieComposition) onLoaded,
Key key, Key key,
LottieFrameBuilder frameBuilder, LottieFrameBuilder frameBuilder,
LottieErrorWidgetBuilder errorBuilder,
double width, double width,
double height, double height,
BoxFit fit, BoxFit fit,
@ -112,6 +115,7 @@ class Lottie extends StatefulWidget {
onLoaded: onLoaded, onLoaded: onLoaded,
key: key, key: key,
frameBuilder: frameBuilder, frameBuilder: frameBuilder,
errorBuilder: errorBuilder,
width: width, width: width,
height: height, height: height,
fit: fit, fit: fit,
@ -133,6 +137,7 @@ class Lottie extends StatefulWidget {
void Function(LottieComposition) onLoaded, void Function(LottieComposition) onLoaded,
Key key, Key key,
LottieFrameBuilder frameBuilder, LottieFrameBuilder frameBuilder,
LottieErrorWidgetBuilder errorBuilder,
double width, double width,
double height, double height,
BoxFit fit, BoxFit fit,
@ -152,6 +157,7 @@ class Lottie extends StatefulWidget {
onLoaded: onLoaded, onLoaded: onLoaded,
key: key, key: key,
frameBuilder: frameBuilder, frameBuilder: frameBuilder,
errorBuilder: errorBuilder,
width: width, width: width,
height: height, height: height,
fit: fit, fit: fit,
@ -173,6 +179,7 @@ class Lottie extends StatefulWidget {
void Function(LottieComposition) onLoaded, void Function(LottieComposition) onLoaded,
Key key, Key key,
LottieFrameBuilder frameBuilder, LottieFrameBuilder frameBuilder,
LottieErrorWidgetBuilder errorBuilder,
double width, double width,
double height, double height,
BoxFit fit, BoxFit fit,
@ -192,6 +199,7 @@ class Lottie extends StatefulWidget {
onLoaded: onLoaded, onLoaded: onLoaded,
key: key, key: key,
frameBuilder: frameBuilder, frameBuilder: frameBuilder,
errorBuilder: errorBuilder,
width: width, width: width,
height: height, height: height,
fit: fit, fit: fit,

View File

@ -44,6 +44,7 @@ class LottieBuilder extends StatefulWidget {
this.options, this.options,
this.onLoaded, this.onLoaded,
this.frameBuilder, this.frameBuilder,
this.errorBuilder,
this.width, this.width,
this.height, this.height,
this.fit, this.fit,
@ -67,6 +68,7 @@ class LottieBuilder extends StatefulWidget {
this.onLoaded, this.onLoaded,
Key key, Key key,
this.frameBuilder, this.frameBuilder,
this.errorBuilder,
this.width, this.width,
this.height, this.height,
this.fit, this.fit,
@ -99,6 +101,7 @@ class LottieBuilder extends StatefulWidget {
this.onLoaded, this.onLoaded,
Key key, Key key,
this.frameBuilder, this.frameBuilder,
this.errorBuilder,
this.width, this.width,
this.height, this.height,
this.fit, this.fit,
@ -122,6 +125,7 @@ class LottieBuilder extends StatefulWidget {
Key key, Key key,
AssetBundle bundle, AssetBundle bundle,
this.frameBuilder, this.frameBuilder,
this.errorBuilder,
this.width, this.width,
this.height, this.height,
this.fit, this.fit,
@ -148,6 +152,7 @@ class LottieBuilder extends StatefulWidget {
this.onLoaded, this.onLoaded,
Key key, Key key,
this.frameBuilder, this.frameBuilder,
this.errorBuilder,
this.width, this.width,
this.height, this.height,
this.fit, this.fit,
@ -279,6 +284,12 @@ class LottieBuilder extends StatefulWidget {
/// ///
final LottieFrameBuilder frameBuilder; final LottieFrameBuilder frameBuilder;
/// A builder function that is called if an error occurs during animation loading.
///
/// If this builder is not provided, it will use the `ErrorWidget` in debug mode
/// and an empty box in release mode.
final LottieErrorWidgetBuilder errorBuilder;
/// If non-null, require the lottie animation to have this width. /// If non-null, require the lottie animation to have this width.
/// ///
/// If null, the lottie animation will pick a size that best preserves its intrinsic /// If null, the lottie animation will pick a size that best preserves its intrinsic
@ -351,6 +362,7 @@ class LottieBuilder extends StatefulWidget {
super.debugFillProperties(properties); super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<LottieProvider>('lottie', lottie)); properties.add(DiagnosticsProperty<LottieProvider>('lottie', lottie));
properties.add(DiagnosticsProperty<Function>('frameBuilder', frameBuilder)); properties.add(DiagnosticsProperty<Function>('frameBuilder', frameBuilder));
properties.add(DiagnosticsProperty<Function>('errorBuilder', errorBuilder));
properties.add(DoubleProperty('width', width, defaultValue: null)); properties.add(DoubleProperty('width', width, defaultValue: null));
properties.add(DoubleProperty('height', height, defaultValue: null)); properties.add(DoubleProperty('height', height, defaultValue: null));
properties.add(EnumProperty<BoxFit>('fit', fit, defaultValue: null)); properties.add(EnumProperty<BoxFit>('fit', fit, defaultValue: null));
@ -396,7 +408,9 @@ class _LottieBuilderState extends State<LottieBuilder> {
future: _loadingFuture, future: _loadingFuture,
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.hasError) { if (snapshot.hasError) {
if (kDebugMode) { if (widget.errorBuilder != null) {
return widget.errorBuilder(context, snapshot.error);
} else if (kDebugMode) {
return ErrorWidget(snapshot.error); return ErrorWidget(snapshot.error);
} }
} }
@ -435,3 +449,10 @@ class _LottieBuilderState extends State<LottieBuilder> {
'loadingFuture', _loadingFuture)); 'loadingFuture', _loadingFuture));
} }
} }
/// Signature used by [Lottie.errorBuilder] to create a replacement widget to
/// render instead of the Lottie animation.
typedef LottieErrorWidgetBuilder = Widget Function(
BuildContext context,
Object error,
);

View File

@ -35,28 +35,28 @@ packages:
name: async name: async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.4.2" version: "2.5.0-nullsafety.1"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
name: boolean_selector name: boolean_selector
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0" version: "2.1.0-nullsafety.1"
characters: characters:
dependency: "direct main" dependency: "direct main"
description: description:
name: characters name: characters
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.0" version: "1.1.0-nullsafety.3"
charcode: charcode:
dependency: "direct main" dependency: "direct main"
description: description:
name: charcode name: charcode
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.3" version: "1.2.0-nullsafety.1"
cli_util: cli_util:
dependency: transitive dependency: transitive
description: description:
@ -70,14 +70,14 @@ packages:
name: clock name: clock
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.1" version: "1.1.0-nullsafety.1"
collection: collection:
dependency: "direct main" dependency: "direct main"
description: description:
name: collection name: collection
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.14.13" version: "1.15.0-nullsafety.3"
convert: convert:
dependency: transitive dependency: transitive
description: description:
@ -112,7 +112,7 @@ packages:
name: fake_async name: fake_async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0" version: "1.2.0-nullsafety.1"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -157,14 +157,14 @@ packages:
name: matcher name: matcher
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.12.8" version: "0.12.10-nullsafety.1"
meta: meta:
dependency: "direct main" dependency: "direct main"
description: description:
name: meta name: meta
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.8" version: "1.3.0-nullsafety.3"
mockito: mockito:
dependency: "direct dev" dependency: "direct dev"
description: description:
@ -199,7 +199,7 @@ packages:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.7.0" version: "1.8.0-nullsafety.1"
pedantic: pedantic:
dependency: transitive dependency: transitive
description: description:
@ -225,56 +225,56 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.7.0" version: "1.8.0-nullsafety.2"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
name: stack_trace name: stack_trace
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.9.5" version: "1.10.0-nullsafety.1"
stream_channel: stream_channel:
dependency: transitive dependency: transitive
description: description:
name: stream_channel name: stream_channel
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0" version: "2.1.0-nullsafety.1"
string_scanner: string_scanner:
dependency: transitive dependency: transitive
description: description:
name: string_scanner name: string_scanner
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.5" version: "1.1.0-nullsafety.1"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
name: term_glyph name: term_glyph
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0" version: "1.2.0-nullsafety.1"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.17" version: "0.2.19-nullsafety.2"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
name: typed_data name: typed_data
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.3.0-nullsafety.3"
vector_math: vector_math:
dependency: "direct main" dependency: "direct main"
description: description:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.8" version: "2.1.0-nullsafety.3"
watcher: watcher:
dependency: transitive dependency: transitive
description: description:
@ -290,4 +290,4 @@ packages:
source: hosted source: hosted
version: "2.2.1" version: "2.2.1"
sdks: sdks:
dart: ">=2.9.0-14.0.dev <3.0.0" dart: ">=2.10.0-110 <2.11.0"