pub package Pub Likes

English Korean

kpostal_plus

A cross-platform Flutter package for Korean postal address search using Kakao postcode service. Enhanced version of kpostal with full mobile and web support in a single unified package.

Features

  • ๐Ÿ“ฑ Cross-platform support: Works seamlessly on iOS, Android, and Web platforms
  • ๐Ÿ” Korean address search: Powered by Kakao postcode service with real-time search
  • ๐ŸŒ Native web integration: DOM manipulation for optimal web performance
  • ๐Ÿ“ Optional geocoding: Get latitude/longitude coordinates
    • Platform geocoding (iOS/Android native)
    • Kakao geocoding API (higher accuracy for Korean addresses)
  • ๐Ÿ›ก๏ธ Null-safe: Full null safety support
  • ๐ŸŽฏ Unified API: Single package for all platforms - no platform-specific dependencies
  • ๐ŸŽจ Customizable UI: Configurable AppBar, colors, and loading indicators
  • ๐ŸŒ Local server support: Optional localhost hosting for offline-capable apps
  • ๐Ÿ”„ Flexible callbacks: Both callback and Navigator.pop return value support

Screenshots

Mobile

Search Screen

Search Result

Custom UI

API Key Dialog

Web

Web Search

Web Result

Installation

Add kpostal_plus to your pubspec.yaml file:

dependencies:
  kpostal_plus: ^1.0.0

Then run:

flutter pub get

Platform Support

Platform Support Notes
Android โœ… Requires internet permission
iOS โœ… Full support
Web โœ… Native DOM integration
macOS โŒ Not supported
Windows โŒ Not supported
Linux โŒ Not supported

Setup

๐Ÿค– Android

Add internet permission to your AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.INTERNET"/>
    <!-- ... -->
</manifest>

For Local Server (Optional)

If you want to use local server hosting (useLocalServer: true), add:

<application
    android:label="your_app"
    android:icon="@mipmap/ic_launcher"
    android:usesCleartextTraffic="true">
    <!-- ... -->
</application>

๐ŸŽ iOS

No additional setup required for basic usage.

For Geocoding (Optional)

If you want to use platform geocoding, add location permissions to your Info.plist:

<key>NSLocationWhenInUseUsageDescription</key>
<string>We need your location to provide accurate address information</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>We need your location to provide accurate address information</string>

For Local Server (Optional)

Add NSAppTransportSecurity to your Info.plist:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

๐ŸŒ Web

No additional setup required. The package automatically handles web integration using native DOM manipulation.

๐Ÿ—บ๏ธ Kakao Geocoding (Optional)

For better geocoding accuracy with Korean addresses:

  1. Go to Kakao Developer Site
  2. Register as a developer and create an app
  3. Add Web Platform and register domain:
    • For GitHub hosting: https://tykann.github.io
    • For local server: http://localhost:8080
  4. Get your JavaScript key from the "App Keys" section
  5. Use it in your code:
KpostalPlusView(
  kakaoKey: 'YOUR_KAKAO_JAVASCRIPT_KEY',
  callback: (result) {
    // result.kakaoLatitude and result.kakaoLongitude will be available
  },
)

Note: For open-source projects, use environment variables or user configuration instead of hardcoding API keys.

Usage

Basic Usage

import 'package:flutter/material.dart';
import 'package:kpostal_plus/kpostal_plus.dart';

// Using callback
TextButton(
  onPressed: () async {
    await Navigator.push(
      context,
      MaterialPageRoute(
        builder: (_) => KpostalPlusView(
          callback: (Kpostal result) {
            print('Postal Code: ${result.postCode}');
            print('Address: ${result.address}');
            print('Coordinates: ${result.latitude}, ${result.longitude}');
          },
        ),
      ),
    );
  },
  child: Text('Search Address'),
)

// Using return value
TextButton(
  onPressed: () async {
    Kpostal? result = await Navigator.push(
      context,
      MaterialPageRoute(builder: (_) => KpostalPlusView()),
    );
    if (result != null) {
      print('Selected address: ${result.address}');
    }
  },
  child: Text('Search Address'),
)

Advanced Usage

KpostalPlusView(
  // [Optional] Custom AppBar
  title: '์ฃผ์†Œ ๊ฒ€์ƒ‰',
  appBarColor: Colors.blue,
  titleColor: Colors.white,
  
  // [Optional] Or use custom AppBar widget
  appBar: AppBar(
    title: Text('Custom AppBar'),
    backgroundColor: Colors.green,
  ),
  
  // [Optional] Enable local server mode
  useLocalServer: true,
  localPort: 8080, // Default: 8080 (range: 1024-49151)
  
  // [Optional] Kakao JavaScript API key for geocoding
  kakaoKey: 'YOUR_KAKAO_JS_KEY',
  
  // [Optional] Custom loading indicator
  loadingColor: Colors.blue,
  onLoading: CircularProgressIndicator(color: Colors.red),
  
  // Callback
  callback: (Kpostal result) {
    print('๐Ÿ  Address Information:');
    print('Postal Code: ${result.postCode}');
    print('Road Address: ${result.roadAddress}');
    print('Jibun Address: ${result.jibunAddress}');
    print('Building Name: ${result.buildingName}');
    
    // Platform geocoding (may be null)
    print('Lat/Lng: ${result.latitude}, ${result.longitude}');
    
    // Kakao geocoding (if kakaoKey provided)
    print('Kakao Lat/Lng: ${result.kakaoLatitude}, ${result.kakaoLongitude}');
  },
)

Use Cases

// ๐Ÿ“ฎ For delivery address
KpostalPlusView(
  title: 'Delivery Address',
  callback: (result) {
    saveDeliveryAddress(
      postCode: result.postCode,
      address: result.address,
    );
  },
)

// ๐Ÿข For company/store registration
KpostalPlusView(
  title: 'Register Store Location',
  kakaoKey: 'YOUR_KEY',
  callback: (result) {
    registerStore(
      name: storeName,
      address: result.address,
      latitude: result.kakaoLatitude ?? result.latitude,
      longitude: result.kakaoLongitude ?? result.longitude,
    );
  },
)

// ๐Ÿ—บ๏ธ For map integration
KpostalPlusView(
  kakaoKey: 'YOUR_KEY', // Required for coordinates
  callback: (result) {
    showOnMap(
      latitude: result.kakaoLatitude ?? result.latitude ?? 0,
      longitude: result.kakaoLongitude ?? result.longitude ?? 0,
    );
  },
)

Parameters

KpostalPlusView

Parameter Type Default Description
title String '์ฃผ์†Œ๊ฒ€์ƒ‰' AppBar title text
appBarColor Color Colors.white AppBar background color
titleColor Color Colors.black AppBar title and icon color
appBar PreferredSizeWidget? null Custom AppBar (overrides title, appBarColor, titleColor)
callback void Function(Kpostal)? null Callback when address is selected
useLocalServer bool false Use localhost server instead of GitHub hosting
localPort int 8080 Localhost port number (1024-49151)
loadingColor Color Colors.blue Loading indicator color
onLoading Widget? null Custom loading widget (overrides loadingColor)
kakaoKey String '' Kakao JavaScript API key for geocoding

Kpostal Model

class Kpostal {
  // Basic Information
  String postCode;              // Postal code (์šฐํŽธ๋ฒˆํ˜ธ)
  String address;               // Full address (์ „์ฒด ์ฃผ์†Œ)
  String addressEng;            // Address in English
  String roadAddress;           // Road address (๋„๋กœ๋ช… ์ฃผ์†Œ)
  String roadAddressEng;        // Road address in English
  String jibunAddress;          // Jibun address (์ง€๋ฒˆ ์ฃผ์†Œ)
  String jibunAddressEng;       // Jibun address in English
  String autoJibunAddress;      // Auto jibun address
  String autoJibunAddressEnglish; // Auto jibun address in English
  
  // Building Information
  String buildingCode;          // Building code
  String buildingName;          // Building name
  String apartment;             // Is apartment (Y/N)
  
  // Address Type
  String addressType;           // R (road) or J (jibun)
  String userSelectedType;      // User selected type (R/J)
  
  // Region Information
  String sido;                  // City/Province (์‹œ/๋„)
  String sidoEng;              // City/Province in English
  String sigungu;              // District (์‹œ/๊ตฐ/๊ตฌ)
  String sigunguEng;           // District in English
  String sigunguCode;          // District code
  String bcode;                // B code
  String bname;                // Dong/Eup/Myeon (๋™/์/๋ฉด)
  String bnameEng;             // Dong/Eup/Myeon in English
  String bname1;               // Bname1
  
  // Road Information
  String roadnameCode;         // Road name code
  String roadname;             // Road name
  String roadnameEng;          // Road name in English
  
  // Additional
  String zonecode;             // Zone code
  String query;                // Search query
  String userLanguageType;     // User language type (K/E)
  
  // Geocoding (may be null)
  double? latitude;            // Platform geocoding latitude
  double? longitude;           // Platform geocoding longitude
  double? kakaoLatitude;       // Kakao geocoding latitude (if kakaoKey provided)
  double? kakaoLongitude;      // Kakao geocoding longitude (if kakaoKey provided)
  
  // Methods
  Future<Location?> get latLng; // Get platform geocoding result
  String get userSelectedAddress; // Get user selected address (road or jibun)
}

Geocoding Support

Platform Geocoding (Free, No API Key)

Uses native iOS (CoreLocation) and Android (Geocoder) services:

  • โœ… Pros: Free, no API key needed
  • โŒ Cons: Less accurate for Korean addresses, may fail, not supported on web

Example:

KpostalPlusView(
  callback: (result) {
    // May be null if geocoding fails
    print('Lat: ${result.latitude}');
    print('Lng: ${result.longitude}');
  },
)

Kakao Geocoding (Requires API Key)

Uses Kakao's geocoding service:

  • โœ… Pros: High accuracy for Korean addresses, works on all platforms (web/mobile)
  • โœ… Pros: More reliable results
  • โš ๏ธ Note: Requires Kakao JavaScript API key

๐Ÿ“Œ Coming in v1.1.0: Fully tested example with working Kakao API key integration and detailed setup guide.

Example:

KpostalPlusView(
  kakaoKey: 'YOUR_KAKAO_JAVASCRIPT_KEY',
  callback: (result) {
    // More reliable for Korean addresses
    print('Kakao Lat: ${result.kakaoLatitude}');
    print('Kakao Lng: ${result.kakaoLongitude}');
  },
)

Recommendation

Use Case Recommendation
Just need address text No geocoding needed โœ…
Show location on map Use Kakao geocoding โญ
Distance calculation Use Kakao geocoding โญ
Route navigation Use Kakao geocoding โญ
Web platform Use Kakao geocoding (required) โญ

Local Server vs GitHub Hosting

GitHub Hosting (Default)

KpostalPlusView(
  // Uses: https://tykann.github.io/kpostal/assets/kakao_postcode.html
  callback: (result) { /* ... */ },
)
  • โœ… Pros: No additional setup, always available
  • โœ… Pros: Faster initial load
  • โŒ Cons: Depends on GitHub Pages availability
  • โŒ Cons: Cannot modify HTML

Local Server

KpostalPlusView(
  useLocalServer: true,
  localPort: 8080,
  callback: (result) { /* ... */ },
)
  • โœ… Pros: Works offline (once HTML is loaded)
  • โœ… Pros: Full control over HTML
  • โœ… Pros: No external dependencies
  • โŒ Cons: Requires additional platform setup (cleartext traffic)
  • โŒ Cons: Slightly slower initial load

Migration Guide

From kpostal or kpostal_web

  1. Update pubspec.yaml:
dependencies:
  # Remove:
  # kpostal: ^x.x.x
  # kpostal_web: ^x.x.x
  
  # Add:
  kpostal_plus: ^1.0.0
  1. Update imports:
// Old
import 'package:kpostal/kpostal.dart';
// or
import 'package:kpostal_web/kpostal_web.dart';

// New
import 'package:kpostal_plus/kpostal_plus.dart';
  1. Update class name:
// Old (kpostal)
KpostalView(
  callback: (result) { /* ... */ },
)

// New (kpostal_plus)
KpostalPlusView(
  callback: (result) { /* ... */ },
)
  1. API remains the same! Only class name changed - all parameters and callbacks work identically.

  2. New features available:

    • Unified mobile + web support
    • Better error handling
    • Improved geocoding
    • More customization options

Example

See the example/ directory for a complete working example app.

Testing

Run tests:

flutter test

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Support

If you encounter any issues or have feature requests, please file an issue on the GitHub repository.

Roadmap

Upcoming in v1.1.0

  • ๐Ÿ—บ๏ธ Kakao Geocoding Examples: Add fully tested examples with Kakao API key integration
  • ๐Ÿ“ Enhanced Geocoding Documentation: Detailed guide for setting up and using Kakao geocoding
  • ๐Ÿงช Geocoding Integration Tests: Comprehensive tests for both platform and Kakao geocoding

Future Plans

  • ๐ŸŒ Multi-language support (Japanese, Chinese)
  • ๐ŸŽจ Additional UI customization options
  • ๐Ÿ“ฆ Reduce package size
  • โšก Performance optimizations

Made with โค๏ธ for the Flutter community

Libraries

kpostal_plus