getAssetPath static method
Generates the asset path for a flag SVG from a country code string.
countryCode
The country code string (e.g., 'us', 'gb', 'fr')
flagSize
The flag size/aspect ratio (defaults to 4x3)
Returns the asset path string that can be used with AssetImage or SvgPicture.asset
Example:
String assetPath = Flag.getAssetPath('us');
// Returns: 'packages/flag/res/4x3/us.svg'
String squareAssetPath = Flag.getAssetPath('us', flagSize: FlagSize.size_1x1);
// Returns: 'packages/flag/res/1x1/us.svg'
Implementation
static String getAssetPath(String countryCode,
{FlagSize flagSize = FlagSize.size_4x3}) {
String countryName = countryCode.toLowerCase();
String folderName = flagSize == FlagSize.size_1x1 ? '1x1' : '4x3';
return 'packages/flag/res/$folderName/$countryName.svg';
}