writeAssetVideoToFile function

Future<File> writeAssetVideoToFile(
  1. String assetPath,
  2. String filePath
)

Writes a video asset to a file on the local file system.

This function takes the path of a video asset bundled with the application and writes its content to a specified file path on the device's file system.

  • Parameters:

    • assetPath: The path to the video asset within the application's assets.
    • filePath: The destination file path where the video will be written.
  • Returns: A Future that resolves to a File object representing the written file.

  • Throws: An exception if the asset cannot be loaded or the file cannot be written.

Implementation

Future<File> writeAssetVideoToFile(String assetPath, String filePath) async {
  final ByteData data = await rootBundle.load(assetPath);
  final buffer = data.buffer;

  final file = File(filePath);

  await file.writeAsBytes(
    buffer.asUint8List(data.offsetInBytes, data.lengthInBytes),
    flush: true,
  );

  return file;
}