diff --git a/android/app/src/main/kotlin/com/adeeteya/markdown_editor/MainActivity.kt b/android/app/src/main/kotlin/com/adeeteya/markdown_editor/MainActivity.kt index 3875f6f..446b972 100644 --- a/android/app/src/main/kotlin/com/adeeteya/markdown_editor/MainActivity.kt +++ b/android/app/src/main/kotlin/com/adeeteya/markdown_editor/MainActivity.kt @@ -51,11 +51,18 @@ class MainActivity : FlutterActivity() { super.configureFlutterEngine(flutterEngine) MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL) .setMethodCallHandler { call, result -> - if (call.method == "getFileContent") { - result.success(fileContentToSend) - fileContentToSend = null // send only once - } else { - result.notImplemented() + when (call.method) { + "getFileContent" -> { + result.success(fileContentToSend) + fileContentToSend = null // send only once + } + "clearFileContent" -> { + fileContentToSend = null + result.success(null) + } + else -> { + result.notImplemented() + } } } } diff --git a/lib/home.dart b/lib/home.dart index 894027b..28dc39b 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -237,6 +237,16 @@ class _HomeState extends State { } } + Future _clearFileContent() async { + try { + await _methodChannel.invokeMethod('clearFileContent'); + } on MissingPluginException { + debugPrint("Method channel not available on this platform"); + } catch (e) { + debugPrint("Error clearing file content: $e"); + } + } + Future _showExitConfirmationDialog() async { return await showDialog( context: context, @@ -443,6 +453,7 @@ class _HomeState extends State { } final bool shouldPop = await _showExitConfirmationDialog(); if (shouldPop && context.mounted) { + await _clearFileContent(); await SystemNavigator.pop(animated: true); } },