getFileFromAssets static method

Future<String> getFileFromAssets(
  1. String documentID,
  2. String path
)

Implementation

static Future<String> getFileFromAssets(
    String documentID, String path) async {
  if (kIsWeb) {
    return Future.value(path);
  } else {
    // on web we copy the assets from asset directory into web directory.
    // therefore on web the implementation of getFileFromAssets should return path
    final byteData = await rootBundle.load(path);

    final newFileName =
        '$documentID-${context.basenameWithoutExtension(path)}-${context.extension(path)}'; // make sure it's a unique filename
    final newFile = File('${Directory.systemTemp.path}/$newFileName');
    await newFile.writeAsBytes(byteData.buffer
        .asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));

    return newFile.path;
  }
}