Compare commits

...

3 Commits

Author SHA1 Message Date
945285175a Set version 3.1.0 2024-02-21 15:19:24 +01:00
cfb29485b0 Use package:http (#334) 2024-02-21 15:11:36 +01:00
31ab666099 Add codecov (#333) 2024-02-21 10:03:45 +01:00
26 changed files with 279 additions and 211 deletions

View File

@ -8,15 +8,12 @@ on:
jobs: jobs:
analyze_and_test: analyze_and_test:
name: Flutter analyze name: Flutter analyze
strategy:
matrix:
flutter: ['stable']
runs-on: macos-13 runs-on: macos-13
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: subosito/flutter-action@v2 - uses: subosito/flutter-action@v2
with: with:
channel: ${{ matrix.flutter }} channel: 'stable'
- run: flutter doctor - run: flutter doctor
- run: flutter --version - run: flutter --version
- run: flutter pub get - run: flutter pub get

22
.github/workflows/coverage.yaml vendored Normal file
View File

@ -0,0 +1,22 @@
name: Coverage
on:
pull_request:
push:
branches:
- master
jobs:
coverage:
name: Coverage
runs-on: macos-13
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
- run: flutter test --coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}

View File

@ -1,3 +1,7 @@
## 3.1.0
- Use `package:http` for `Lottie.network`. This allows to drop dependency on `dart:html` and be compatible with `wasm`.
- Fix new lints
## 3.0.0 ## 3.0.0
- Add `renderCache` parameter. - Add `renderCache` parameter.

View File

@ -18,7 +18,6 @@ linter:
avoid_js_rounded_ints: true avoid_js_rounded_ints: true
avoid_positional_boolean_parameters: true avoid_positional_boolean_parameters: true
avoid_redundant_argument_values: true avoid_redundant_argument_values: true
avoid_returning_null_for_future: true
avoid_setters_without_getters: true avoid_setters_without_getters: true
avoid_type_to_string: true avoid_type_to_string: true
avoid_unused_constructor_parameters: true avoid_unused_constructor_parameters: true

View File

@ -77,10 +77,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: ffi name: ffi
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878" sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.0" version: "2.1.2"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -107,22 +107,14 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
golden_toolkit:
dependency: "direct dev"
description:
name: golden_toolkit
sha256: "8f74adab33154fe7b731395782797021f97d2edc52f7bfb85ff4f1b5c4a215f0"
url: "https://pub.dev"
source: hosted
version: "0.15.0"
http: http:
dependency: "direct main" dependency: "direct main"
description: description:
name: http name: http
sha256: d4872660c46d929f6b8a9ef4e7a7eff7e49bbf0c4ec3f385ee32df5119175139 sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.1.2" version: "1.2.1"
http_parser: http_parser:
dependency: transitive dependency: transitive
description: description:
@ -135,10 +127,34 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: js name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.6.7" version: "0.7.1"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "2.0.1"
lints: lints:
dependency: transitive dependency: transitive
description: description:
@ -161,39 +177,47 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "3.0.0" version: "3.1.0"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.12.16" version: "0.12.16+1"
material_color_utilities: material_color_utilities:
dependency: transitive dependency: transitive
description: description:
name: material_color_utilities name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.5.0" version: "0.8.0"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.10.0" version: "1.11.0"
mime:
dependency: transitive
description:
name: mime
sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2"
url: "https://pub.dev"
source: hosted
version: "1.0.5"
path: path:
dependency: "direct main" dependency: "direct main"
description: description:
name: path name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.8.3" version: "1.9.0"
path_provider: path_provider:
dependency: "direct main" dependency: "direct main"
description: description:
@ -214,10 +238,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: path_provider_foundation name: path_provider_foundation
sha256: "19314d595120f82aca0ba62787d58dde2cc6b5df7d2f0daf72489e38d1b57f2d" sha256: "5a7999be66e000916500be4f15a3633ebceb8302719b47b9cc49ce924125350f"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.3.1" version: "2.3.2"
path_provider_linux: path_provider_linux:
dependency: transitive dependency: transitive
description: description:
@ -262,10 +286,26 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: pointycastle name: pointycastle
sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c" sha256: "43ac87de6e10afabc85c445745a7b799e04de84cebaa4fd7bf55a5e1e9604d29"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.7.3" version: "3.7.4"
shelf:
dependency: "direct dev"
description:
name: shelf
sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4
url: "https://pub.dev"
source: hosted
version: "1.4.1"
shelf_static:
dependency: "direct dev"
description:
name: shelf_static
sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e
url: "https://pub.dev"
source: hosted
version: "1.1.2"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -335,14 +375,22 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.4" version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "13.0.0"
web: web:
dependency: transitive dependency: transitive
description: description:
name: web name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 sha256: "1d9158c616048c38f712a6646e317a3426da10e884447626167240d45209cbad"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.3.0" version: "0.5.0"
win32: win32:
dependency: transitive dependency: transitive
description: description:
@ -360,5 +408,5 @@ packages:
source: hosted source: hosted
version: "1.0.4" version: "1.0.4"
sdks: sdks:
dart: ">=3.2.0 <4.0.0" dart: ">=3.3.0 <4.0.0"
flutter: ">=3.16.0" flutter: ">=3.16.0"

View File

@ -23,7 +23,8 @@ dev_dependencies:
flutter_lints: flutter_lints:
flutter_test: flutter_test:
sdk: flutter sdk: flutter
golden_toolkit: shelf:
shelf_static:
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec

View File

@ -0,0 +1,9 @@
import 'dart:io';
import 'package:shelf/shelf_io.dart';
import 'package:shelf_static/shelf_static.dart';
void main() async {
var server = await serve(
createStaticHandler('build/web'), InternetAddress.loopbackIPv4, 0);
print('Listen on http://${server.address.host}:${server.port}/index.html');
}

View File

@ -1,5 +1,7 @@
import 'dart:io' as io;
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:http/http.dart' as http;
import '../lottie.dart'; import '../lottie.dart';
import 'composition.dart'; import 'composition.dart';
import 'l.dart'; import 'l.dart';
@ -95,7 +97,7 @@ class Lottie extends StatefulWidget {
/// Creates a widget that displays an [LottieComposition] obtained from a [File]. /// Creates a widget that displays an [LottieComposition] obtained from a [File].
static LottieBuilder file( static LottieBuilder file(
Object /*io.File|html.File*/ file, { io.File file, {
Animation<double>? controller, Animation<double>? controller,
FrameRate? frameRate, FrameRate? frameRate,
bool? animate, bool? animate,
@ -200,6 +202,8 @@ class Lottie extends StatefulWidget {
/// Creates a widget that displays an [LottieComposition] obtained from the network. /// Creates a widget that displays an [LottieComposition] obtained from the network.
static LottieBuilder network( static LottieBuilder network(
String url, { String url, {
http.Client? client,
Map<String, String>? headers,
Animation<double>? controller, Animation<double>? controller,
FrameRate? frameRate, FrameRate? frameRate,
bool? animate, bool? animate,
@ -225,6 +229,8 @@ class Lottie extends StatefulWidget {
}) => }) =>
LottieBuilder.network( LottieBuilder.network(
url, url,
client: client,
headers: headers,
controller: controller, controller: controller,
frameRate: frameRate, frameRate: frameRate,
animate: animate, animate: animate,

View File

@ -1,6 +1,8 @@
import 'dart:async'; import 'dart:async';
import 'dart:io' as io;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:http/http.dart' as http;
import 'composition.dart'; import 'composition.dart';
import 'frame_rate.dart'; import 'frame_rate.dart';
import 'lottie.dart'; import 'lottie.dart';
@ -67,6 +69,7 @@ class LottieBuilder extends StatefulWidget {
/// Creates a widget that displays an [LottieComposition] obtained from the network. /// Creates a widget that displays an [LottieComposition] obtained from the network.
LottieBuilder.network( LottieBuilder.network(
String src, { String src, {
http.Client? client,
Map<String, String>? headers, Map<String, String>? headers,
this.controller, this.controller,
this.frameRate, this.frameRate,
@ -91,6 +94,7 @@ class LottieBuilder extends StatefulWidget {
this.renderCache, this.renderCache,
bool? backgroundLoading, bool? backgroundLoading,
}) : lottie = NetworkLottie(src, }) : lottie = NetworkLottie(src,
client: client,
headers: headers, headers: headers,
imageProviderFactory: imageProviderFactory, imageProviderFactory: imageProviderFactory,
decoder: decoder, decoder: decoder,
@ -107,7 +111,7 @@ class LottieBuilder extends StatefulWidget {
/// `android.permission.READ_EXTERNAL_STORAGE` permission. /// `android.permission.READ_EXTERNAL_STORAGE` permission.
/// ///
LottieBuilder.file( LottieBuilder.file(
Object /*io.File|html.File*/ file, { io.File file, {
this.controller, this.controller,
this.frameRate, this.frameRate,
this.animate, this.animate,

View File

@ -2,54 +2,54 @@ import 'dart:ui';
import 'value/drop_shadow.dart'; import 'value/drop_shadow.dart';
/// Property values are the same type as the generic type of their corresponding /// Property values are the same type as the generic type of their corresponding
/// {@link LottieValueCallback}. With this, we can use generics to maintain type safety /// [LottieValueCallback]. With this, we can use generics to maintain type safety
/// of the callbacks. /// of the callbacks.
/// ///
/// Supported properties: /// Supported properties:
/// Transform: /// Transform:
/// {@link #TRANSFORM_ANCHOR_POINT} /// {TRANSFORM_ANCHOR_POINT}
/// {@link #TRANSFORM_POSITION} /// {TRANSFORM_POSITION}
/// {@link #TRANSFORM_OPACITY} /// {TRANSFORM_OPACITY}
/// {@link #TRANSFORM_SCALE} /// {TRANSFORM_SCALE}
/// {@link #TRANSFORM_ROTATION} /// {TRANSFORM_ROTATION}
/// {@link #TRANSFORM_SKEW} /// {TRANSFORM_SKEW}
/// {@link #TRANSFORM_SKEW_ANGLE} /// {TRANSFORM_SKEW_ANGLE}
/// ///
/// Fill: /// Fill:
/// {@link #COLOR} (non-gradient) /// {#COLOR} (non-gradient)
/// {@link #OPACITY} /// {#OPACITY}
/// {@link #COLOR_FILTER} /// {#COLOR_FILTER}
/// ///
/// Stroke: /// Stroke:
/// {@link #COLOR} (non-gradient) /// {#COLOR} (non-gradient)
/// {@link #STROKE_WIDTH} /// {#STROKE_WIDTH}
/// {@link #OPACITY} /// {#OPACITY}
/// {@link #COLOR_FILTER} /// {#COLOR_FILTER}
/// ///
/// Ellipse: /// Ellipse:
/// {@link #POSITION} /// {#POSITION}
/// {@link #ELLIPSE_SIZE} /// {#ELLIPSE_SIZE}
/// ///
/// Polystar: /// Polystar:
/// {@link #POLYSTAR_POINTS} /// {#POLYSTAR_POINTS}
/// {@link #POLYSTAR_ROTATION} /// {#POLYSTAR_ROTATION}
/// {@link #POSITION} /// {#POSITION}
/// {@link #POLYSTAR_INNER_RADIUS} (star) /// {#POLYSTAR_INNER_RADIUS} (star)
/// {@link #POLYSTAR_OUTER_RADIUS} /// {#POLYSTAR_OUTER_RADIUS}
/// {@link #POLYSTAR_INNER_ROUNDEDNESS} (star) /// {#POLYSTAR_INNER_ROUNDEDNESS} (star)
/// {@link #POLYSTAR_OUTER_ROUNDEDNESS} /// {#POLYSTAR_OUTER_ROUNDEDNESS}
/// ///
/// Repeater: /// Repeater:
/// All transform properties /// All transform properties
/// {@link #REPEATER_COPIES} /// {#REPEATER_COPIES}
/// {@link #REPEATER_OFFSET} /// {#REPEATER_OFFSET}
/// {@link #TRANSFORM_ROTATION} /// {#TRANSFORM_ROTATION}
/// {@link #TRANSFORM_START_OPACITY} /// {#TRANSFORM_START_OPACITY}
/// {@link #TRANSFORM_END_OPACITY} /// {#TRANSFORM_END_OPACITY}
/// ///
/// Layers: /// Layers:
/// All transform properties /// All transform properties
/// {@link #TIME_REMAP} (composition layers only) /// {#TIME_REMAP} (composition layers only)
abstract class LottieProperty { abstract class LottieProperty {
/// ColorInt **/ /// ColorInt **/
static const Color color = Color(0x00000001); static const Color color = Color(0x00000001);

View File

@ -66,7 +66,7 @@ class Buffer {
} }
/// Reads and discards {@code byteCount} bytes from this source. Throws an /// Reads and discards {@code byteCount} bytes from this source. Throws an
/// {@link java.io.EOFException} if the source is exhausted before the /// [Exception] if the source is exhausted before the
/// requested bytes can be skipped. /// requested bytes can be skipped.
void skip(int byteCount) { void skip(int byteCount) {
_start += byteCount; _start += byteCount;

View File

@ -857,7 +857,7 @@ class JsonUtf8Reader extends JsonReader {
/// Returns the next character in the stream that is neither whitespace nor a /// Returns the next character in the stream that is neither whitespace nor a
/// part of a comment. When this returns, the returned character is always at /// part of a comment. When this returns, the returned character is always at
/// {@code buffer.getByte(0)}. /// {buffer.getByte(0)}.
int _nextNonWhitespace(bool throwOnEof) { int _nextNonWhitespace(bool throwOnEof) {
// This code uses ugly local variables 'p' and 'l' representing the 'pos' // This code uses ugly local variables 'p' and 'l' representing the 'pos'
// and 'limit' fields respectively. Using locals rather than fields saves // and 'limit' fields respectively. Using locals rather than fields saves

View File

@ -74,7 +74,7 @@ class AssetLottie extends LottieProvider {
} }
@override @override
bool operator ==(dynamic other) { bool operator ==(Object other) {
if (other.runtimeType != runtimeType) return false; if (other.runtimeType != runtimeType) return false;
return other is AssetLottie && return other is AssetLottie &&
other.keyName == keyName && other.keyName == keyName &&

View File

@ -1,12 +1,13 @@
import 'dart:io' as io;
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:path/path.dart' as p;
import '../composition.dart'; import '../composition.dart';
import '../lottie_image_asset.dart'; import '../lottie_image_asset.dart';
import 'load_fonts.dart'; import 'load_fonts.dart';
import 'load_image.dart'; import 'load_image.dart';
import 'lottie_provider.dart'; import 'lottie_provider.dart';
import 'provider_io.dart' if (dart.library.html) 'provider_web.dart' as io;
@immutable @immutable
class FileLottie extends LottieProvider { class FileLottie extends LottieProvider {
@ -15,9 +16,13 @@ class FileLottie extends LottieProvider {
super.imageProviderFactory, super.imageProviderFactory,
super.decoder, super.decoder,
super.backgroundLoading, super.backgroundLoading,
}); }) : assert(
!kIsWeb,
'Lottie.file is not supported on Flutter Web. '
'Consider using either Lottie.asset or Lottie.network instead.',
);
final Object /*io.File|html.File*/ file; final io.File file;
@override @override
Future<LottieComposition> load({BuildContext? context}) { Future<LottieComposition> load({BuildContext? context}) {
@ -25,9 +30,9 @@ class FileLottie extends LottieProvider {
LottieComposition composition; LottieComposition composition;
var args = (file, decoder); var args = (file, decoder);
if (backgroundLoading) { if (backgroundLoading) {
composition = await compute(loadFileAndParse, args); composition = await compute(_loadFileAndParse, args);
} else { } else {
composition = await loadFileAndParse(args); composition = await _loadFileAndParse(args);
} }
for (var image in composition.images.values) { for (var image in composition.images.values) {
@ -44,26 +49,28 @@ class FileLottie extends LottieProvider {
LottieComposition composition, LottieImageAsset lottieImage) { LottieComposition composition, LottieImageAsset lottieImage) {
var imageProvider = getImageProvider(lottieImage); var imageProvider = getImageProvider(lottieImage);
imageProvider ??= io.loadImageForFile(file, lottieImage); var imagePath = p.url
.join(p.dirname(file.path), lottieImage.dirName, lottieImage.fileName);
imageProvider ??= FileImage(io.File(imagePath));
return loadImage(composition, lottieImage, imageProvider); return loadImage(composition, lottieImage, imageProvider);
} }
@override @override
bool operator ==(dynamic other) { bool operator ==(Object other) {
if (other.runtimeType != runtimeType) return false; if (other.runtimeType != runtimeType) return false;
return other is FileLottie && io.areFilesEqual(file, other.file); return other is FileLottie && file.path == other.file.path;
} }
@override @override
int get hashCode => file.hashCode; int get hashCode => file.hashCode;
@override @override
String toString() => '$runtimeType(file: ${io.filePath(file)})'; String toString() => '$runtimeType(file: ${file.path})';
} }
Future<LottieComposition> loadFileAndParse( Future<LottieComposition> _loadFileAndParse(
(Object, LottieDecoder?) args) async { (io.File, LottieDecoder?) args) async {
var bytes = await io.loadFile(args.$1); var bytes = await args.$1.readAsBytes();
return await LottieComposition.fromBytes(bytes, decoder: args.$2); return await LottieComposition.fromBytes(bytes, decoder: args.$2);
} }

View File

@ -50,7 +50,7 @@ class MemoryLottie extends LottieProvider {
} }
@override @override
bool operator ==(dynamic other) { bool operator ==(Object other) {
if (other.runtimeType != runtimeType) return false; if (other.runtimeType != runtimeType) return false;
//TODO(xha): compare bytes content //TODO(xha): compare bytes content

View File

@ -2,24 +2,26 @@ import 'dart:async';
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:http/http.dart' as http;
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
import '../composition.dart'; import '../composition.dart';
import '../lottie_image_asset.dart'; import '../lottie_image_asset.dart';
import 'load_fonts.dart'; import 'load_fonts.dart';
import 'load_image.dart'; import 'load_image.dart';
import 'lottie_provider.dart'; import 'lottie_provider.dart';
import 'provider_io.dart' if (dart.library.html) 'provider_web.dart' as network;
@immutable @immutable
class NetworkLottie extends LottieProvider { class NetworkLottie extends LottieProvider {
NetworkLottie( NetworkLottie(
this.url, { this.url, {
this.client,
this.headers, this.headers,
super.imageProviderFactory, super.imageProviderFactory,
super.decoder, super.decoder,
super.backgroundLoading, super.backgroundLoading,
}); });
final http.Client? client;
final String url; final String url;
final Map<String, String>? headers; final Map<String, String>? headers;
@ -28,21 +30,30 @@ class NetworkLottie extends LottieProvider {
return sharedLottieCache.putIfAbsent(this, () async { return sharedLottieCache.putIfAbsent(this, () async {
var resolved = Uri.base.resolve(url); var resolved = Uri.base.resolve(url);
LottieComposition composition; var client = this.client ?? http.Client();
var args = (resolved, headers, decoder); try {
if (backgroundLoading) { var bytes = await client.readBytes(resolved, headers: headers);
composition = await compute(downloadAndParse, args);
} else { LottieComposition composition;
composition = await downloadAndParse(args); if (backgroundLoading) {
composition = await compute(parseJsonBytes, (bytes, decoder));
} else {
composition =
await LottieComposition.fromBytes(bytes, decoder: decoder);
}
for (var image in composition.images.values) {
image.loadedImage ??= await _loadImage(resolved, composition, image);
}
await ensureLoadedFonts(composition);
return composition;
} finally {
if (this.client == null) {
client.close();
}
} }
for (var image in composition.images.values) {
image.loadedImage ??= await _loadImage(resolved, composition, image);
}
await ensureLoadedFonts(composition);
return composition;
}); });
} }
@ -60,7 +71,7 @@ class NetworkLottie extends LottieProvider {
} }
@override @override
bool operator ==(dynamic other) { bool operator ==(Object other) {
if (other.runtimeType != runtimeType) return false; if (other.runtimeType != runtimeType) return false;
return other is NetworkLottie && return other is NetworkLottie &&
other.url == url && other.url == url &&
@ -73,9 +84,3 @@ class NetworkLottie extends LottieProvider {
@override @override
String toString() => '$runtimeType(url: $url)'; String toString() => '$runtimeType(url: $url)';
} }
Future<LottieComposition> downloadAndParse(
(Uri, Map<String, String>?, LottieDecoder?) args) async {
var bytes = await network.loadHttp(args.$1, headers: args.$2);
return await LottieComposition.fromBytes(bytes, decoder: args.$3);
}

View File

@ -1,44 +0,0 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:path/path.dart' as p;
import '../lottie_image_asset.dart';
final HttpClient _sharedHttpClient = HttpClient()..autoUncompress = false;
Future<Uint8List> loadHttp(Uri uri, {Map<String, String>? headers}) async {
var request = await _sharedHttpClient.getUrl(uri);
headers?.forEach((String name, String value) {
request.headers.add(name, value);
});
final response = await request.close();
if (response.statusCode != HttpStatus.ok) {
throw Exception('Http error. Status code: ${response.statusCode} for $uri');
}
final bytes = await consolidateHttpClientResponseBytes(response);
if (bytes.lengthInBytes == 0) {
throw Exception('NetworkImage is an empty file: $uri');
}
return bytes;
}
Future<Uint8List> loadFile(Object file) {
return (file as File).readAsBytes();
}
bool areFilesEqual(Object f1, Object f2) =>
(f1 as File).path == (f2 as File).path;
String filePath(Object file) {
return (file as File).path;
}
ImageProvider loadImageForFile(Object file, LottieImageAsset lottieImage) {
var fileIo = file as File;
var imagePath = p.url
.join(p.dirname(fileIo.path), lottieImage.dirName, lottieImage.fileName);
return FileImage(File(imagePath));
}

View File

@ -1,39 +0,0 @@
import 'dart:html';
import 'dart:typed_data';
import 'package:flutter/rendering.dart';
import '../lottie_image_asset.dart';
// ignore_for_file: avoid_web_libraries_in_flutter
Future<Uint8List> loadHttp(Uri uri, {Map<String, String>? headers}) async {
var request = await HttpRequest.request(uri.toString(),
requestHeaders: headers, responseType: 'blob');
return _loadBlob(request.response as Blob);
}
Future<Uint8List> loadFile(Object file) {
return _loadBlob(file as File);
}
Future<Uint8List> _loadBlob(Blob file) async {
var reader = FileReader();
reader.readAsArrayBuffer(file);
await reader.onLoadEnd.first;
if (reader.readyState != FileReader.DONE) {
throw Exception('Error while reading blob');
}
return reader.result! as Uint8List;
}
String filePath(Object file) {
return (file as File).relativePath ?? '';
}
bool areFilesEqual(Object f1, Object f2) => f1 == f2;
ImageProvider loadImageForFile(Object file, LottieImageAsset lottieImage) {
throw UnimplementedError();
}

View File

@ -96,7 +96,7 @@ class MiscUtils {
/// it to the accumulator list. /// it to the accumulator list.
/// ///
/// Any {@link KeyPathElementContent} should call through to this as its implementation of /// Any {@link KeyPathElementContent} should call through to this as its implementation of
/// {@link KeyPathElementContent#resolveKeyPath(KeyPath, int, List, KeyPath)}. /// {KeyPathElementContent#resolveKeyPath(KeyPath, int, List, KeyPath)}.
static void resolveKeyPath( static void resolveKeyPath(
KeyPath keyPath, KeyPath keyPath,
int depth, int depth,

View File

@ -331,7 +331,7 @@ class ResolvedValueDelegate<T> {
/// to multiple contents. In that case, the callbacks's value will apply to all of them. /// to multiple contents. In that case, the callbacks's value will apply to all of them.
/// <p> /// <p>
/// Internally, this will check if the {@link KeyPath} has already been resolved with /// Internally, this will check if the {@link KeyPath} has already been resolved with
/// {@link #resolveKeyPath(KeyPath)} and will resolve it if it hasn't. /// {#resolveKeyPath(KeyPath)} and will resolve it if it hasn't.
void addValueCallback(LottieDrawable drawable) { void addValueCallback(LottieDrawable drawable) {
var invalidate = false; var invalidate = false;
if (valueDelegate.keyPath.isEmpty) { if (valueDelegate.keyPath.isEmpty) {

View File

@ -5,18 +5,18 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: _fe_analyzer_shared name: _fe_analyzer_shared
sha256: eb376e9acf6938204f90eb3b1f00b578640d3188b4c8a8ec054f9f479af8d051 sha256: "0b2f2bd91ba804e53a61d757b986f89f1f9eaed5b11e4b2f5a2468d86d6c9fc7"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "64.0.0" version: "67.0.0"
analyzer: analyzer:
dependency: "direct dev" dependency: "direct dev"
description: description:
name: analyzer name: analyzer
sha256: "69f54f967773f6c26c7dcb13e93d7ccee8b17a641689da39e878d5cf13b06893" sha256: "37577842a27e4338429a1cbc32679d508836510b056f1eedf0c8d20e39c1383d"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "6.2.0" version: "6.4.1"
archive: archive:
dependency: "direct main" dependency: "direct main"
description: description:
@ -139,14 +139,54 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.2" version: "2.1.2"
http:
dependency: "direct main"
description:
name: http
sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
js: js:
dependency: transitive dependency: transitive
description: description:
name: js name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.6.7" version: "0.7.1"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "2.0.1"
lints: lints:
dependency: transitive dependency: transitive
description: description:
@ -159,26 +199,26 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.12.16" version: "0.12.16+1"
material_color_utilities: material_color_utilities:
dependency: transitive dependency: transitive
description: description:
name: material_color_utilities name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.5.0" version: "0.8.0"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.10.0" version: "1.11.0"
package_config: package_config:
dependency: transitive dependency: transitive
description: description:
@ -191,18 +231,18 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: path name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.8.3" version: "1.9.0"
pointycastle: pointycastle:
dependency: transitive dependency: transitive
description: description:
name: pointycastle name: pointycastle
sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c" sha256: "43ac87de6e10afabc85c445745a7b799e04de84cebaa4fd7bf55a5e1e9604d29"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.7.3" version: "3.7.4"
pub_semver: pub_semver:
dependency: transitive dependency: transitive
description: description:
@ -280,6 +320,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.4" version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "13.0.0"
watcher: watcher:
dependency: transitive dependency: transitive
description: description:
@ -292,10 +340,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: web name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 sha256: "1d9158c616048c38f712a6646e317a3426da10e884447626167240d45209cbad"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.3.0" version: "0.5.0"
yaml: yaml:
dependency: "direct dev" dependency: "direct dev"
description: description:
@ -305,5 +353,5 @@ packages:
source: hosted source: hosted
version: "3.1.2" version: "3.1.2"
sdks: sdks:
dart: ">=3.2.0 <4.0.0" dart: ">=3.3.0 <4.0.0"
flutter: ">=3.16.0" flutter: ">=3.16.0"

View File

@ -1,6 +1,6 @@
name: lottie name: lottie
description: Render After Effects animations natively on Flutter. This package is a pure Dart implementation of a Lottie player. description: Render After Effects animations natively on Flutter. This package is a pure Dart implementation of a Lottie player.
version: 3.0.0 version: 3.1.0
repository: https://github.com/xvrh/lottie-flutter repository: https://github.com/xvrh/lottie-flutter
funding: funding:
@ -14,6 +14,7 @@ dependencies:
archive: ^3.0.0 archive: ^3.0.0
flutter: flutter:
sdk: flutter sdk: flutter
http: ^1.0.0
path: ^1.8.0 path: ^1.8.0
vector_math: ^2.1.0 vector_math: ^2.1.0

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB