getAssetPackPath method
Future<String?>
getAssetPackPath({
- required String assetPackName,
- required int count,
- required String namingPattern,
- 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
nullif an error occurs.
Throws:
- PlatformException if an error occurs on the platform side.
- UnsupportedError if the platform is unsupported.
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;
}