getByName static method

Country? getByName(
  1. String name, {
  2. bool withLowerCase = false,
})

Get country by name

May use withLowerCase flag to compare each country name with lower case letters

Implementation

static Country? getByName(
  String name, {
  bool withLowerCase = false,
}) {
  bool handleWhere(Country country) {
    return withLowerCase
        ? country.name.toLowerCase() == name
        : country.name == name;
  }

  return toList().firstWhereOrNull(handleWhere);
}