build method
IBAN
build(
[ - bool fillRandom = true,
- bool validate = true
])
Implementation
IBAN build([bool fillRandom = true, bool validate = true]) {
if (fillRandom && _countryValue == null) {
final List<Country> supportedCountries =
BbanStructure.supportedCountries();
_countryValue = supportedCountries[randInt(supportedCountries.length)];
}
final BbanStructure? structure =
_countryValue == null ? null : BbanStructure.forCountry(_countryValue!);
if (structure == null) {
throw Exception("shouldn't happen");
}
_fillMissingFieldsRandomly(fillRandom);
// iban is formatted with default check digit.
final String formattedIban = _formatIban();
final String checkDigit = iban_util.calculateCheckDigit(formattedIban);
// replace default check digit with calculated check digit
final ibanValue = iban_util.replaceCheckDigit(formattedIban, checkDigit);
if (validate) {
iban_util.validate(ibanValue);
}
return IBAN(ibanValue);
}