readFile static method

Future<Uint8List?> readFile(
  1. String folderPath,
  2. String fileName
)

Reads the contents of a binary file with the given fileName from the specified folderPath.

Returns the file contents as a Uint8List, or null if the file or folder does not exist.

Implementation

static Future<Uint8List?> readFile(String folderPath, String fileName) async {
  final targetDir = Directory(folderPath);
  if (!await targetDir.exists()) {
    return null;
  }
  String filePath = "${targetDir.path}/$fileName";
  final file = File(filePath);

  if (await file.exists()) {
    return await file.readAsBytes();
  }
  return null;
}