Skip to content

Commit

Permalink
Merge branch 'feature/dispose-controller'
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-szeto committed Oct 24, 2024
2 parents 26a5c8e + a6abd92 commit 4eaee86
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ios/Classes/SwiftPencilKitPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ public class SwiftPencilKitPlugin: NSObject, FlutterPlugin {
private enum PencilKitUtil {
static func handleMethodCall(call: FlutterMethodCall, result: @escaping FlutterResult) {
if call.method == "checkAvailable" {
result(ProcessInfo().operatingSystemVersion.majorVersion >= 13)
if #available(iOS 13.0, *) {
result(true)
} else {
result(false)
}
} else {
result(FlutterMethodNotImplemented)
}
}
}
13 changes: 13 additions & 0 deletions lib/src/pencil_kit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ class _PencilKitState extends State<PencilKit> {
return _buildUnAvailable();
}
}

@override
void dispose() {
_controller?._dispose(); // Dispose of the controller
_controller = null;
super.dispose();
}
}

class PencilKitController {
Expand Down Expand Up @@ -261,4 +268,10 @@ class PencilKitController {
/// ```
Future<void> loadBase64Data(String base64Data) =>
_channel.invokeMethod('loadBase64Data', base64Data);

/// Dispose the controller and release resources
void _dispose() {
_channel.invokeMethod('dispose');
_channel.setMethodCallHandler(null); // Remove the method call handler
}
}

0 comments on commit 4eaee86

Please sign in to comment.