Currency class abstract
Abstract base class for currency operations following ISO 4217 standards.
This class provides a common interface for all currency types and includes static methods to manage and retrieve currency instances according to ISO 4217 codes or locale information.
Use this class to:
- Retrieve currency instances by code or locale.
- Access currency metadata such as symbol, numeric code, or display name.
- Work with all available currencies in a consistent manner.
Example usage:
// Get a currency by ISO code
final usd = Currency.getInstance('USD');
// Get a currency by locale
final eur = Currency.getInstanceFromLocale(Locale('de', 'DE'));
// List all available currencies
final allCurrencies = Currency.getAllCurrencies();
// Access currency properties
print(usd.symbol); // $
print(eur.displayName); // Euro
Constructors
- Currency()
Properties
- currencyCode → String
-
The ISO 4217 currency code (e.g., "USD", "EUR", "GBP").
no setter
- defaultFractionDigits → int
-
The default number of fraction digits for this currency.
no setter
- displayName → String
-
The display name of this currency in English.
no setter
- hashCode → int
-
Returns a hash code based on the currency code.
no setteroverride
- numericCode → int
-
The numeric code for this currency as defined by ISO 4217.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- symbol → String
-
The currency symbol (e.g., "$", "€", "£").
no setter
Methods
-
compareTo(
Currency other) → int - Compares this currency to another by currency code.
-
copyWith(
{String? currencyCode, String? symbol, int? defaultFractionDigits, int? numericCode, String? displayName}) → Currency - Creates a copy of this currency with optional overrides.
-
getDisplayName(
[Locale? locale]) → String -
Returns the display name, optionally localized by
locale
. -
getSymbol(
[Locale? locale]) → String -
Returns the currency symbol, optionally localized by
locale
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDetailedString(
) → String - Returns a detailed string representation including all currency properties.
-
toString(
) → String -
Returns the currency code as the string representation.
override
Operators
-
operator ==(
Object other) → bool -
Compares this currency to another for equality based on currency code.
override
Static Methods
-
getAllCurrencies(
) → List< Currency> - Returns a list of all available Currency instances.
-
getAvailableCurrencies(
) → Set< String> - Returns a set of all available ISO 4217 currency codes.
-
getInstance(
String currencyCode) → Currency - Abstract base class for currency operations following ISO 4217 standards.
-
getInstanceFromLocale(
Locale locale) → Currency - Abstract base class for currency operations following ISO 4217 standards.
-
isSupported(
String currencyCode) → bool - Returns true if the given currency code is supported.