How nikolaydymura/flutter_health_connect works
Main components
• Flutter Plugin Interface (Dart Code): This is found in the “lib” directory. It contains the public API (flutter_health_connect.dart) and supporting modules such as data types, records, and unit conversion classes. These components abstract the Health Connect operations (reading/writing health records, checking permissions, etc.) for the Flutter app.
• Android Native Module: Located in the “android” directory (especially under src/main/kotlin/dev/duynp/flutter_health_connect), it contains platform-specific plugin implementation (e.g., FlutterHealthConnectPlugin.kt, Consts.kt). This layer handles the communication between Flutter and the native Android Health Connect API.
• iOS Native Module: Found in the “ios” directory (Classes folder and the podspec), it implements the native side for iOS, ensuring that the plugin can work across platforms although the primary focus is on Android.
• Example Application: The “example” directory holds a sample Flutter app that demonstrates use cases of the plugin, including UI examples and sample code usage in main.dart. This shows how the plugin is integrated within a working Flutter project.
• External Health Connect Service: Although not part of the codebase, the integration with Google Health Connect on Android is a key external dependency. This external system is accessed via the native layer.
Relationships and interactions
• The Flutter application (or any consumer app) invokes functions from the Dart plugin API in the “lib” folder.
• The Dart API communicates with the platform-specific native code through Flutter’s platform channels.
• On Android, the native plugin calls Health Connect APIs (after ensuring permissions are declared and requested).
• iOS native code (if used) similarly interacts with any corresponding Apple health providers.
• The example app, contained in the “example” directory, demonstrates these interactions end-to-end.
Architectural patterns and design principles
• Plugin Architecture: The project follows a typical Flutter plugin design, with a clear separation between the Dart interface (cross-platform) and native implementations (platform-specific).
• Abstraction layers: The “lib” folder abstracts out health record types, unit conversions, and data model definitions. This keeps the business logic separated from native integration details.
• Modular Design: Each health record (e.g., StepsRecord, ExerciseSessionRecord) is modeled in isolated files, enhancing maintainability and extensibility.
• Configuration and Dependency Management: The inclusion of Gradle files in the Android folder and podspec/iOS Xcode project files encapsulates platform-specific build and dependency configurations.
Relevant technologies and frameworks
• Flutter & Dart – For the cross-platform API and application logic.
• Android (Kotlin) – For the native integration with Health Connect.
• iOS (Objective-C/Swift) – For the native integration on the iOS side.
• Gradle – For building the Android plugin.
• Xcode & CocoaPods – For building and integrating the iOS module.