Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Emulate loadStructuredBinaryData on all versions"
This reverts commit 5e79e10.
  • Loading branch information
arnemolland committed Feb 28, 2023
commit 3ebefd09566d538fb8fa86617cbf6e0e68d9563c
26 changes: 11 additions & 15 deletions flutter/lib/src/sentry_asset_bundle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,24 +339,20 @@ class SentryAssetBundle implements AssetBundle {
return _loadStructuredBinaryDataWrapper<T>(key, parser);
}

// Helper method that emulates the loadStructuredBinaryData method present on
// Flutter 3.8 and later, but not on earlier versions. This is equivalent to
// the following code:
//
// Future<T> loadStructuredBinaryData<T>(
// String key,
// FutureOr<T> Function(ByteData data) parser,
// ) async {
// return (_bundle as dynamic).loadStructuredBinaryData<T>(key, parser) as Future<T>;
// }
//
// but it works on all Flutter versions. Can be safely refactored back to the
// above code once we drop support for Flutter versions < 3.8.
// helper method to have a "typesafe" method
Future<T> _loadStructuredBinaryDataWrapper<T>(
String key,
FutureOr<T> Function(ByteData data) parser,
) async {
final ByteData data = await load(key);
return parser(data);
// The loadStructuredBinaryData method exists as of Flutter greater than 3.8
// Previous versions don't have it, but later versions do.
// We can't use `extends` in order to provide this method because this is
// a wrapper and thus the method call must be forwarded.
// On Flutter versions <=3.8 we can't forward this call.
// On later version the call gets correctly forwarded.
// The error doesn't need to handled since it can't be called on earlier versions,
// and it's correctly forwarded on later versions.
return (_bundle as dynamic).loadStructuredBinaryData<T>(key, parser)
as Future<T>;
}
}
12 changes: 6 additions & 6 deletions flutter/test/sentry_asset_bundle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void main() {
);

test(
'loadStructuredBinaryData: does not create any spans and just forwards the call to the underlying assetbundle if disabled',
'loadStructuredBinaryData: does not create any spans and just forwords the call to the underlying assetbundle if disabled',
() async {
final sut = fixture.getSut(structuredDataTracing: false);
final tr = fixture._hub.startTransaction(
Expand All @@ -355,7 +355,7 @@ void main() {

final tracer = (tr as SentryTracer);

expect(tracer.children.length, 1);
expect(tracer.children.length, 0);
},
);

Expand Down Expand Up @@ -417,7 +417,7 @@ void main() {
final tracer = (tr as SentryTracer);
var span = tracer.children.first;

expect(tracer.children.length, 3);
expect(tracer.children.length, 2);

expect(span.status, SpanStatus.internalError());
expect(span.finished, true);
Expand All @@ -428,7 +428,7 @@ void main() {
'AssetBundle.loadStructuredBinaryData<String>: test.txt',
);

span = tracer.children.last;
span = tracer.children[1];

expect(span.status, SpanStatus.internalError());
expect(span.finished, true);
Expand Down Expand Up @@ -463,7 +463,7 @@ void main() {
final tracer = (tr as SentryTracer);
var span = tracer.children.first;

expect(tracer.children.length, 3);
expect(tracer.children.length, 2);

expect(span.status, SpanStatus.ok());
expect(span.finished, true);
Expand All @@ -473,7 +473,7 @@ void main() {
'AssetBundle.loadStructuredBinaryData<String>: test.txt',
);

span = tracer.children.last;
span = tracer.children[1];

expect(span.status, SpanStatus.ok());
expect(span.finished, true);
Expand Down