How pichillilorenzo/flutter_inappwebview works
Project’s Role
• It is not a traditional frontend/backend app but a federated plugin library.
• It exposes a Dart API (flutter_inappwebview) that Flutter apps consume.
• It comprises a Platform Interface package plus multiple platform‐specific implementations.
• It also houses an example app, dev code‐generation packages, and test infrastructure.
Spotlight the Major Components
1. Example Flutter App
– Located under flutter_inappwebview/example.
– Demonstrates usage of the Dart API.
2. Core Dart Wrapper (flutter_inappwebview)
– Exposes classes like InAppWebView, InAppBrowser, CookieManager, etc.
– Depends on the Platform Interface.
3. Platform Interface (flutter_inappwebview_platform_interface)
– Defines abstract contracts, data types, channel names.
– Shared dependency of all platform implementations.
4. Platform Implementations
– Android (flutter_inappwebview_android) → Java/Kotlin classes using Android WebView & Chrome Custom Tabs.
– iOS (flutter_inappwebview_ios) → Swift/Obj-C with WKWebView, SafariViewController.
– macOS (flutter_inappwebview_macos) → Swift with WKWebView.
– Windows (flutter_inappwebview_windows) → C++/WinRT wrapping WebView2.
– Web (flutter_inappwebview_web) → Dart + JavaScript bridge for browser environment.
5. Native WebView Engines & OS Services
– Android WebView, WKWebView on Apple platforms, Edge WebView2 on Windows, DOM Web APIs in browser.
6. Dev Packages
– flutter_inappwebview_internal_annotations (defines annotations).
– generators (build_runner builders that generate the g.dart files).
7. Test & CI Infrastructure
– test_node_server (HTTPS server for integration tests).
– scripts folder (publish.sh, test.sh, CI workflows).
Interactions & Data Flow
• Flutter App → calls → Core Dart Wrapper
• Core Dart Wrapper → delegates via → Platform Interface (MethodChannel)
• Platform Interface → invokes → Platform Implementation
• Platform Implementation → calls native WebView APIs → performs web actions
• Native WebView → sends events back → Platform Implementation → method channel → Core Dart Wrapper → App
• Dev Packages (build time) annotate and generate code in Dart packages.
• Test Server (external) provides assets and secure endpoints for integration tests.
Architectural Patterns
• Federated Plugin Pattern – separates interface from implementations.
• Platform Channels – MethodChannel/BasicMessageChannel bridging Dart ↔ native.
• Code Generation – build_runner + custom builders generate serialization code (G-files).
• Monorepo Structure – root organizes multiple pub packages in a single repository.
Putting It All Together
• Layer 1 (App Layer)
– Example Flutter App
• Layer 2 (Plugin API Layer)
– flutter_inappwebview (Dart)
• Layer 3 (Interface Layer)
– flutter_inappwebview_platform_interface
• Layer 4 (Implementation Layer)
– flutter_inappwebview_android → Android WebView
– flutter_inappwebview_ios → WKWebView/SafariViewController
– flutter_inappwebview_macos → WKWebView
– flutter_inappwebview_windows → WebView2
– flutter_inappwebview_web → DOM/JS Bridge
• Layer 5 (Native Engines & OS)
– Underlying WebView components on each platform
• Side Components
– Dev Packages (annotations, generators)
– Test Server & CI scripts
Final Touches
• Number or group related components.
• Federated pattern: separate interface vs implementations.