Skip to main content

address_formatter 0.4.0 copy "address_formatter: ^0.4.0" to clipboard
address_formatter: ^0.4.0 copied to clipboard

Formats address components into human-readable address strings using OpenCage templates for countries worldwide.

Address Formatter #

Overview #

A Dart package for formatting address components into human-readable address strings. It uses the address templates from OpenCage to produce correctly formatted addresses for countries worldwide.

Pass a components map — for example Nominatim's address object (with addressdetails=1) or Photon's properties.

Installation #

Add the package to your pubspec.yaml:

dependencies:
  address_formatter: ^0.4.0

API #

formatAddress(Map<String, dynamic> components, {
  String? fallbackCountryCode,
  bool appendCountry = true,
  bool abbreviate = false,
})

formatAddressSingleLine(Map<String, dynamic> components, {
  String? fallbackCountryCode,
  bool appendCountry = true,
  bool abbreviate = false,
})

formatAddress returns a newline-separated string. formatAddressSingleLine joins those lines with ', '.

  • abbreviate: shorten road and place names (Avenue → Ave).
  • appendCountry: include the country name (default true).
  • fallbackCountryCode: ISO 3166-1 alpha-2 code when country_code is missing.

Use #

print(formatAddress({
  'country_code': 'US',
  'house_number': '301',
  'road': 'Hamilton Avenue',
  'neighbourhood': 'Crescent Park',
  'city': 'Palo Alto',
  'postcode': '94303',
  'county': 'Santa Clara County',
  'state': 'California',
  'country': 'United States',
}));
/*
301 Hamilton Avenue
Palo Alto, CA 94303
United States of America
*/

print(formatAddressSingleLine({
  'house_number': '17',
  'road': 'Rue du Médecin-Colonel Calbairac',
  'postcode': '31000',
  'city': 'Toulouse',
  'country': 'France',
  'country_code': 'FR',
}));
// 17 Rue du Médecin-Colonel Calbairac, 31000 Toulouse, France

License #

This project is licensed under the MIT License. See the LICENSE for details. The OpenCage address templates are also MIT; see THIRD_PARTY_LICENSES.

Contributions #

Contributions welcome.

Acknowledgements #

0
likes
160
points
126
downloads

Documentation

API reference

Publisher

verified publisherg.watch

Weekly Downloads

Formats address components into human-readable address strings using OpenCage templates for countries worldwide.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

mustache_template

More

Packages that depend on address_formatter