getAssetPackPath method

  1. @override
Future<String?> getAssetPackPath({
  1. required String assetPackName,
  2. required int count,
  3. required String namingPattern,
  4. required String fileExtension,
})
override

Gets the file path for the specified asset pack.

This method determines the storage location of an asset pack, downloading it if necessary, depending on the platform:

  • On Android, it fetches the asset pack path.
  • On iOS, it downloads the assets and returns the path to the folder where the resources are stored.

Parameters:

  • assetPackName: The name of the asset pack to fetch.
  • count: The number of assets in the asset pack.
  • namingPattern: The naming pattern for the assets (e.g., "asset_%d").
  • fileExtension: The file extension for the assets (e.g., "png", "mp3").

Returns:

  • A String representing the path to the asset pack folder, or null if an error occurs.

Throws:

Implementation

@override
Future<String?> getAssetPackPath({
  required String
      assetPackName, // specify the name of the asset pack to fetch
  required int count, // specify the number of assets in the pack to fetch
  required String namingPattern, // specify the naming pattern of the assets
  required String fileExtension, // Specify the file extension for the asset
}) async {
  String? assetPath;
  try {
    if (Platform.isAndroid) {
      assetPath = await methodChannel
          .invokeMethod('getAssets', {'assetPack': assetPackName});
    } else if (Platform.isIOS) {
      assetPath = await methodChannel.invokeMethod('getDownloadResources', {
        'tag': assetPackName,
        'namingPattern': namingPattern,
        'assetRange': count,
        'extension': fileExtension,
      });
    } else {
      debugPrint('Unsupported platform');
      throw UnsupportedError('Platform not supported');
    }
  } on PlatformException catch (e) {
    debugPrint("Failed to fetch asset pack path: ${e.message}");
    return null;
  } on UnsupportedError catch (e) {
    debugPrint("Error: ${e.message}");
    return null;
  }
  return assetPath;
}