flutter_postal_jp

pub package style: effective dart Platform Badge License: MIT

I have published an alternative package that uses Japan Post Office APIs. I recommend using that instead. The package is available here.

A Dart package for retrieving Japanese postal address information from a postal code.

This package utilizes the Zip Cloud web service.

demo!

Features

  • Retrieve address information (prefecture, city, town) based on a 7-digit Japanese postal code.
    • 7桁の日本の郵便番号から住所情報(都道府県、市区町村)を取得します。
  • Provides PostalCodeService to fetch data from an external API.
    • 外部APIからデータを取得するPostalCodeServiceを提供します。
  • Returns data as AddressInfo objects, including Japanese address components and kana readings.
    • 日本語の住所構成要素とかな読みを含むAddressInfoオブジェクトとしてデータを返します。
  • Handles API errors and returns ApiFailure with error messages.
    • APIエラーを処理し、エラーメッセージとともにApiFailureを返します。

Getting started

  1. Add the dependency to your pubspec.yaml file:

    dependencies:
      postal_jp: ^<latest_version> # Replace with the latest version
    
  2. Install the package:

    flutter pub get
    

Usage

import 'package:postal_jp/postal_jp.dart';

void main() async {
  final service = PostalJP();
  final result = await service.getAddress(postalCode: '0790177');
  switch (result) {
    case ApiSuccess(data: var addressInfoList):
      for (var address in addressInfoList) {
        print(
          'Address: ${address.address1} ${address.address2} ${address.address3}',
        );
      }
    case ApiFailure():
      print('Error: ${result.error}');
  }
}

Libraries

postal_jp