How johyunchol/kakao_map_plugin works
Project Type and Purpose
• This project is a Flutter plugin that wraps the Kakao Maps JavaScript API. It allows Flutter developers to integrate Kakao Maps into their applications using a web-based approach (through webview_flutter), rather than native SDK libraries.
• The plugin is organized as a library (with a “lib” directory containing multiple subcomponents) along with native integration examples and sample apps (in the “example”, “android”, “ios”, and “macos” folders).
Analyzing the File Structure
• Top-level directories include:
– android, ios, macos: Native integration directories for each platform with platform-specific build files, manifest files, and native (Kotlin/Swift/Objective-C) code.
– lib: Contains the Flutter plugin’s Dart source code. It is organized into subdirectories like “src/basic”, “src/model”, “src/protocol”, “src/repository”, “src/service”, “src/constants” etc. This clearly defines layers such as:
▪ Basic building blocks for map functionality (e.g., KakaoMap, KakaoMapController, Marker, Polygon, etc.).
▪ Models representing data (e.g., LatLng, LatLngBounds, Address etc.).
▪ Protocol/message structures for communicating with Kakao backend services.
▪ Repositories and services that manage authentication (via the AuthRepository) and perform tasks like address search, coordinate transformation, and so on.
– example: A full Flutter application demonstrating how to use the plugin. It includes its own Android, iOS, macos subfolders and Flutter UI code written in Dart.
• Build and configuration files (pubspec.yaml, gradle files, AndroidManifest.xml, Info.plist, etc.) indicate that the project is designed for multi-platform support and integration with external services, namely the Kakao Maps JavaScript API.
Examining the README for Additional Insights
• The README details how to initialize the plugin with a JavaScript key (including a singleton AuthRepository). It shows several sample code snippets that demonstrate usage such as displaying a map, adding markers, working with overlays (e.g., Circle, Polyline, Polygon, Rectangle), and clustering – this implies numerous “services” and “UI widget” components working together.
• Configuration comments for both Android and iOS also highlight the need to set up proper permissions and settings to render a webview that displays the map content.
a. Flutter UI Components:
– KakaoMap Widget: The primary entry widget that developers use.
– Other UI layer components in the example app that interact with the map widget (e.g., home_screen.dart and various library screens).
b. Plugin Core Library (within the “lib” directory):
– Basic map components (e.g., classes in lib/src/basic such as KakaoMap, KakaoMapController, Marker, etc.).
– Model Layer: Represents geographic data structures and UI models (e.g., LatLng, LatLngBounds, and address-related models).
– Protocol and Repository Layers: Encapsulate network calls and backend communication (e.g., AuthRepository, address_search_service, etc.) to Kakao services.
– Service Layer: Business logic that handles search functionality, coordinate conversion, and other map-related operations.
c. Platform-Specific Native Integration:
– Android: Kotlin-based native integration (found under android/src/main/kotlin/kr/co/kkensu/kakao_map_plugin) with proper gradle configuration.
– iOS: Swift and Objective-C bridging code (under ios/Classes) to support the plugin on iOS.
– macOS: Minimal integration with auto-generated plugin registrant files.
d. External Dependencies:
– webview_flutter: Used to load and control the Kakao maps JavaScript library.
– Kakao Maps API: The underlying external mapping service powered by a JavaScript key.
– The widget uses the plugin’s controller and communicates downward to the library’s basic layer components.
– Service/Repository layers are used to initialize and manage the state (e.g., AuthRepository initialization with the JavaScript key) and provide data to the UI.
– The core library communicates with platform-specific native code via Flutter’s platform channels, enabling calls to native (Kotlin for Android, Swift/Objective-C for iOS) functionalities if needed.
• Architectural Patterns:
– The plugin is constructed using a layered architecture:
▪ Presentation/UI Layer (Flutter widget/front-end)
▪ Business Logic Layer (services, repositories)
▪ Data Model/Protocol Layer (models, protocol definitions)
▪ Platform Abstraction Layer (native Android, iOS, and macOS integrations facilitated by platform channels)
– The AuthRepository is designed as a singleton; this is an architectural pattern ensuring that map initialization and authentication occur once.
– Use of dependency inversion can be implied by having platform interfaces (e.g., method channel implementations) decoupled from the high-level business logic.
Instructing the Principal Software Engineer
– Start by outlining the Flutter UI components and how they interact with the plugin’s cross-platform code.
– Then, drill down into the plugin’s internal Dart structure – showing models, services, repositories, and controllers.
– Finally, illustrate the separate native modules for Android and iOS, and highlight the communication paths (using Flutter’s platform channels) that allow the Dart code to call native code if needed.
• Clear labels for each block/component.
– Application initialization and configuration (e.g., via AuthRepository).
– Data flows between layers (UI → Controller → Service → Repository → (optionally) Native Code).
– Callback flows and event handling (e.g., onMapCreated, button clicks, etc.).
– UI components (Flutter widget screens)
– Business logic and service layers (in “lib/src”)
– Native integration layers (Android/iOS directories)
– External dependencies (webview_flutter and Kakao Maps API)
• Remember to detail every major component and annotate their responsibilities as explained above.