FLUTTER ECOSYSTEM

leancodepl/address

處理國際化庫。以各種語言格式化各種實體地址,並建立本地化的地址表單。

地址 專案封面
Stars
12
Forks
1
最近推送(UTC)
2023年8月15日
專案狀態
未封存
LeanCode GitHub avatar
GITHUB Organization

LeanCode ↗

We're a custom software studio that delivers end-to-end solutions for various industries. Experts in Flutter, .NET, and React.

語言DartSwiftKotlinObjective-C

技術主題

此儲存庫發佈的套件

使用的依賴

依賴清單 3 項

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

展開 / 收合專案 README

address

Pub Version GitHub test workflow status

Addresses internationalization library. Format various physical addresses in various languages and build localized address forms.

Usage

Formatting address to display

Given you have some address:

final address = Address(
  fullName: 'Nicole Martin',
  addressLine1: '123 Sherbrooke St',
  city: 'Montreal',
  zone: 'QC',
  postalCode: 'H3G 2A6',
  country: 'CA',
);

You can format it to your desired format:

final englishFormatter = AddressFormatter('en');
print(englishFormatter.formatDisplay(address));

// [
//   'NICOLE MARTIN',
//   '123 SHERBROOKE ST',
//   'MONTREAL QC  H3G 2A6',
//   'CANADA'
// ]

final frenchFormatter = AddressFormatter('fr');
print(frenchFormatter.formatDisplay(address));

// [
//   'Nicole Martin',
//   '123 Sherbrooke St',
//   'Montreal (Québec)  H2G 2A6',
//   'CANADA'
// ]

Address form layout

You can also get localized format of an address form with all obligatory and optional fields along with their labels and descriptions.

final addressFormatter = AddressFormatter('en');
final formFormat = addressFormatter.formatForm('US');

// formFormat = [
//   // other fields: full name, addressLine1, addressLine2, city
//   AddressFormFieldInformation(
//     label: 'State',
//     obligatory: true,
//     availableValues: {
//       // (...)
//       'TX': 'Texas',
//       // (...)
//     },
//   ),
//   // other fields: zip code
// ]

You can use this information to build e.g. a Flutter form. You can see how to do this by looking into the example.