getStateByCode function

Future<State?> getStateByCode(
  1. String countryCode,
  2. String stateCode
)

Get a state from its code and its belonging country code

Implementation

Future<State?> getStateByCode(
  String countryCode,
  String stateCode,
) async {
  final states = await _loadStates();

  final res = states.where((state) {
    return state.countryCode == countryCode && state.isoCode == stateCode;
  }).toList();

  return res.isEmpty ? null : res.first;
}