FlutterSentryAttachment.fromAsset constructor

FlutterSentryAttachment.fromAsset(
  1. String key, {
  2. String? filename,
  3. AssetBundle? bundle,
  4. String? type,
  5. String? contentType,
  6. bool? addToTransactions,
})

Creates an attachment from an asset out of a AssetBundle. If no bundle is given, it's using the rootBundle. Typically you want to use it like this:

final attachment = Attachment.fromAsset(
  'assets/foo_bar.txt',
  bundle: DefaultAssetBundle.of(context),
);

Implementation

FlutterSentryAttachment.fromAsset(
  String key, {
  String? filename,
  AssetBundle? bundle,
  String? type,
  String? contentType,
  bool? addToTransactions,
}) : super.fromLoader(
        loader: () async {
          final data = await (bundle ?? rootBundle).load(key);
          return data.buffer.asUint8List();
        },
        filename: filename ?? Uri.parse(key).pathSegments.last,
        attachmentType: type,
        contentType: contentType,
        addToTransactions: addToTransactions,
      );