findStateByCode method

T findStateByCode(
  1. String code
)

Finds a state by its unique code.

  • code: The code to search for.
  • Returns: The state object with the matching code.
  • Throws: An exception if no state with the given code is found.

Implementation

T findStateByCode(String code) {
  for (var state in states) {
    if (getCode(state).equalsIgnoreCase(code)) {
      return state;
    }
  }
  throw Exception("Invalid code provided!");
}