diff --git a/ios/Classes/SwiftPencilKitPlugin.swift b/ios/Classes/SwiftPencilKitPlugin.swift index 057988e..f76246d 100644 --- a/ios/Classes/SwiftPencilKitPlugin.swift +++ b/ios/Classes/SwiftPencilKitPlugin.swift @@ -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) } } } diff --git a/lib/src/pencil_kit.dart b/lib/src/pencil_kit.dart index a759f07..6706c09 100644 --- a/lib/src/pencil_kit.dart +++ b/lib/src/pencil_kit.dart @@ -145,6 +145,13 @@ class _PencilKitState extends State { return _buildUnAvailable(); } } + + @override + void dispose() { + _controller?._dispose(); // Dispose of the controller + _controller = null; + super.dispose(); + } } class PencilKitController { @@ -261,4 +268,10 @@ class PencilKitController { /// ``` Future 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 + } }