findAssetPath method

String findAssetPath(
  1. String path,
  2. String audioType, {
  3. String? package,
})

Implementation

String findAssetPath(String path, String audioType, {String? package}) {
  if (audioType == 'network' ||
      audioType == 'liveStream' ||
      audioType == 'file') {
    return path;
  }
  // in web, assets are packaged in a /assets/ folder
  // if you want '/asset/3' as described in pubspec
  // it will be in /assets/asset/3

  /* for release mode, need to change the 'url', remove the /#/ and add /asset before */
  if (path.startsWith('/')) {
    path = path.replaceFirst('/', '');
  }
  if (package != null) {
    path = 'packages/$package/$path';
  }

  // URL-encode each path segment so filenames with spaces or unicode
  // characters are fetchable by the browser.
  final encoded = path.split('/').map(Uri.encodeComponent).join('/');
  path = '${web.window.location.href.replaceAll('/#/', '')}/assets/$encoded';
  return path;
}