saveAndLaunchFile static method

Future<void> saveAndLaunchFile(
  1. List<int> bytes,
  2. String fileName
)

To save the Excel file in the device

Implementation

static Future<void> saveAndLaunchFile(
    List<int> bytes, String fileName) async {
  final base64String = base64.encode(bytes);
  final hrefValue =
      'data:application/octet-stream;charset=utf-16le;base64,$base64String';

  final anchor = web.HTMLAnchorElement()
    ..href = hrefValue
    ..setAttribute('download', fileName);
  web.document.body!.appendChild(anchor);
  anchor.click();
  anchor.remove();
}