Skip to content

Commit

Permalink
Force embed assets when getting the preview for the sharelinks
Browse files Browse the repository at this point in the history
- enables overriding the exporttype on export
- forces the "preview" riv file that gets exported to be exported "embedded"
- allows us to handle exceptions when decoding images (more to be done here, but this at least lets us avoid crashing without being able to catch exceptions https://api.flutter.dev/flutter/dart-ui/decodeImageFromList.html)

Diffs=
185b76201 Force embed assets when getting the preview for the sharelinks (#5608)
8e82475b8 Baseline Origin (#5577)
8b49fcbc5 Add option to quantize time to whole frames of framerate. (#5578)
b8e5473b9 Follow path should respect constrained component rotation if orient is off (#5601)

Co-authored-by: Maxwell Talbot <talbot.maxwell@gmail.com>
  • Loading branch information
mjtalbot and mjtalbot committed Jul 18, 2023
1 parent a86d5e5 commit 0f08139
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1292ebe56e5996ed2baec99732d630651f00cec0
185b7620160bc2661c700ac033db8b483d02271e
32 changes: 27 additions & 5 deletions lib/src/asset_loader.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:rive/src/asset.dart';
Expand Down Expand Up @@ -26,7 +27,11 @@ class CDNAssetLoader extends FileAssetLoader {

@override
Future<bool> load(FileAsset asset) async {
// TODO: Question (Max): Do we have a URL builder? Improve this.
// TODO (Max): Do we have a URL builder?
// TODO (Max): We should aim to get loading errors exposed where
// possible, this includes failed network requests but also
// failed asset.decode

var url = asset.cdnBaseUrl;

if (!url.endsWith('/')) {
Expand All @@ -37,10 +42,27 @@ class CDNAssetLoader extends FileAssetLoader {
);

final res = await http.get(Uri.parse(url));
await asset.decode(
Uint8List.view(res.bodyBytes.buffer),
);
return true;

if ((res.statusCode / 100).floor() == 2) {
try {
await asset.decode(
Uint8List.view(res.bodyBytes.buffer),
);
} on Exception catch (e) {
// only print in debug
assert(() {
debugPrint('''Unable to parse response ${asset.runtimeType}.
- Url: $url
- Exception: $e''');
return true;
}());
return false;
}

return true;
} else {
return false;
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/rive_core/assets/image_asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class ImageAsset extends ImageAssetBase {
image = await parseBytes(bytes);
}

static Future<ui.Image?> parseBytes(Uint8List bytes) {
final completer = Completer<ui.Image?>();
ui.decodeImageFromList(bytes, completer.complete);
return completer.future;
static Future<ui.Image?> parseBytes(Uint8List bytes) async {
final codec = await ui.instantiateImageCodec(bytes);
final frameInfo = await codec.getNextFrame();
return frameInfo.image;
}

Image getDefaultObject() => Image()
Expand Down

0 comments on commit 0f08139

Please sign in to comment.