Commit 0a939df

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2023-10-12 13:10:16
document proceedure for adding more platform specific code
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent b42821b
Changed files (1)
lib
platform_integration
lib/platform_integration/platform_client.dart
@@ -1,8 +1,19 @@
 import 'package:flutter/services.dart';
 
+/// Class that hosts platform specific functions for sharing files, loading files, saving files and asking for
+/// directory permissions.
+///
+/// Steps for expanding this class:
+/// - If the purpose of the class is not related to storage create a new class with a different [_platformChannel] path.
+/// - Open the android folder in Android Studio.
+/// - Implement the new method in `StorageProvider.kt`.
+/// - Add method name and arguments as a condition to the `onMethodCall` in the same class.
+/// - Implement a helper function to this class that calls uses the platform channel (like [shareFile]).
 class PlatformClient {
   /// Platform channel for sharing files, loading files, saving files and asking for directory permissions.
-  static const storagePlatform = MethodChannel('bloodPressureApp.derdilla.com/storage');
+  static const _platformChannel = MethodChannel('bloodPressureApp.derdilla.com/storage');
+
+  PlatformClient._create();
 
   /// Share a file from application storage.
   ///
@@ -10,9 +21,11 @@ class PlatformClient {
   /// will be shared with the specified [mimeType].
   ///
   /// The user will be shown the Android Sharesheet.
+  /// 
+  /// The returned value indicates whether a [PlatformException] was thrown.
   static Future<bool> shareFile(String path, String mimeType) async {
     try {
-      await storagePlatform.invokeMethod('shareFile', {
+      await _platformChannel.invokeMethod('shareFile', {
         'path': path,
         'mimeType': mimeType
       });